I am trying to query a mysql database using PHP.
I have a function in a seperate PHP (PHP File A) file which I call to connect to the database in PHP File B:
PHP File A:
===========
PHP File B:
===========
My problem is that when I open PHP File B, I get the error:
"Warning: sqlsrv_query() expects parameter 1 to be resource, null given"
What am I doing wrong here? If I incorporate the code from A into B it connects and queries fine, but I want this in a separate file so I can control the connection details in a single location.
I include the PHP File A in the Header of PHP File B, and the 'RS Connect' Function returns 'Connection Established' right above the Warning error.
Any help appreciated!
I have a function in a seperate PHP (PHP File A) file which I call to connect to the database in PHP File B:
PHP File A:
===========
PHP:
function RS_Connect()
{
// Database Connection Settings
$RS_Server = "RSDB";
$RS_Settings = array("UID"=>"ReadOnly", "PWD"=>"password", "Database"=>"RSDB");
$RS_Connection = sqlsrv_connect($RS_Server, $RS_Settings);
if($RS_Connection)
{
echo "Connection Established.\n";
}
else
{
echo "Connection Could Not Be Established.\n";
die( print_r( sqlsrv_errors(), true));
}
}
PHP File B:
===========
PHP:
// Connect To SQL Database
RS_Connect();
// SQL Query
$Query = "SELECT tblMobUsers.UserID, tblMobUsers.Fullname ";
$Query.= "FROM tblMobUsers";
// Execute SQL Query
$Query_Results = sqlsrv_query($RS_Connection,$Query);
// Display Number of Results
$Query_Results_Count = sqlsrv_num_rows($Query_Results);
My problem is that when I open PHP File B, I get the error:
"Warning: sqlsrv_query() expects parameter 1 to be resource, null given"
What am I doing wrong here? If I incorporate the code from A into B it connects and queries fine, but I want this in a separate file so I can control the connection details in a single location.
I include the PHP File A in the Header of PHP File B, and the 'RS Connect' Function returns 'Connection Established' right above the Warning error.
Any help appreciated!