I want to check if the database 'example' exist in my ms sql server
The code doesnt seem to work :/
Im getting,
sqlsrv_num_rows expects parameter 1 to be in resource
config.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');
?>