我要檢查數據庫「示例」在我的MS SQL Server中存在
似乎沒有工作代碼:/
即時得到,
sqlsrv_num_rows預計參數1是資源PHP檢查MS SQL數據庫是否存在?
配置.PHP
<?php
$userID=$_SESSION['userID'];
$serverName = '';
$uid = '';
$pwd = '';
$connectionInfo = array("UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$userID);
$conn = sqlsrv_connect($serverName, $connectionInfo);
?>
file.php
<?php
function checkForUserDB($userID){
$_SESSION['userID'] = $userID;
include('config.php');
$sql="SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME ='".$userID."'";
$result=sqlsrv_query($conn,$sql, array(), array("Scrollable" => 'static'));
$count=sqlsrv_num_rows($result);
if($count==1){
echo "Database Exist!";
}
else{
echo "Database does not exist!";
}
}
checkForUserDB('example');
?>
[警告可能重複:SQLSRV \ _num \ _rows()預計參數1是資源,布爾給定](https://stackoverflow.com/questions/35343796/warning-sqlsrv-num-rows-expects-parameter-1-to-be-resource-boolean-given) – jirigracik