I hope someone can help with this one.
I would like to replace the sever login code with a file that I can call. The idea is that I have several servers I need to log into and I don't want to keep replacing this code with new. Instead I will use an If Else routine to call the right login details.
So what I have so far is a robconfig.php file with the server login details and error code
<?php
$serverName = "//serverName\instanceName";
$connectionInfo = array( "Database"=>"database", "UID"=>"xx", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
?>
And I've tried placing it into my existing php file using exec() system() and passthru() but have not been able to get the variables e.g. "$conn" passed through to the rest of the script
<?php
// CONNECT TO SERVER
system('php -q robfig.php');
// DATA for BOX TABLE 1
$tsqBl = "SELECT * FROM FactBox";
$stmtB1 = sqlsrv_query( $conn, $tsqBl);
$dataB1 = "";
while( $row = sqlsrv_fetch_array( $stmtB1, SQLSRV_FETCH_NUMERIC)){
$dataB1 .= "$row[2]";
}
// ECHO STATEMENTS TO CHECK DATA IF WORKING PROPERLY
echo "$dataB1";
// CLOSE THE CONNECTION TO THE SERVER
sqlsrv_free_stmt( $stmtB1);
sqlsrv_close( $conn);
?>
I get this error message.
Notice: Undefined variable: conn in C:\xampp\htdocs\phpConfigTest.php on line 8
Any direction would be appreciated.
Thanks Rob