Please i am trying to connect to an mssql database on a different machine. Below is my code but i just keep getting a blank page.
I dont know what the issue may be. i have installed php and the mssql drivers.
<?php $uid = "******"; $pwd = "***$$****"; $DB = "***********"; $serverName = "192.***.**.***"; $connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=> $DB, "ReturnDatesAsStrings" => true); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } ?>
Advertisement
Answer
I would suggest that you display the connection error using sqlsrv_errors()
.
Load the PHP drivers in php.ini
file and restart the server.
extension=php_pdo_sqlsrv_54_ts.dll extension=php_sqlsrv_54_ts.dll
Please see the following example:
<?php $serverName = "serverNamesqlexpress"; //serverNameinstanceName // Since UID and PWD are not specified in the $connectionInfo array, // The connection will be attempted using Windows Authentication. $connectionInfo = array( "Database"=>"dbName"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } ?>
For more info: http://php.net/manual/en/function.sqlsrv-connect.php