0

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

1
  • 1
    have you tried use require_once 'robfig.php'? Commented Nov 14, 2014 at 9:58

1 Answer 1

1

Use require_once('robconfig.php');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.