Hi all
I have 3 pcs on my network
A - MS Sql server
B - a MS Server 2008 SP2 with IIS & PHP installed
C - a MS Server 2008 with no iis - but has NTalk server
both B & C have a desktop app that can read the Ms Sql data on "A", so firewall is OK
I can get B & C to do simple php things, so php works, and with phpinfo.php I can see a section for "SQLSRV" so I believe the MS driver is installed on both as php_sqlsrv_54_nts.dll in the ext folder, and extension set in php.ini for this path.
But I cant access the MsSql data from either B or C using simple connection strings I have Googled to test the connection, I get a an error "Connection could not be established"
Has anyone been able to connect to MS Sql ? Any hints would be appreciated.
Thanks
PLEASE NOTE
THERE IS BEER AVAILABLE TO WHOEVER SOLVES THIS
-------[ Using SqlSrv_connect() shows echo 2 then throws error...
-------[ Using MsSql_connect() DOES NOT show echo 2 - it just plain dies
<?php
$serverName = "192.168.0.121,1433";
//$serverName = "s2003"; //serverName\instanceName
$connectionInfo = array( "Database"=>"BCDS_WMS", "UID"=>"sa", "PWD"=>"password");
// $conn = mssql_connect( $serverName, $connectionInfo);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
echo " <br> 2..";
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
==================[ UPDATE ]=========
Following the Googles I read it might need odbc installed, so I did and using odbc_connect( ) - this works OK - but still cant connect with sqlsrv_connect( ) which I need to use (to use customers php code)
<?php
$virtual_dsn = 'DRIVER={SQL Server};SERVER=s2003;DATABASE=BCDS_Wms';
$connection = odbc_connect($virtual_dsn,'sa','password') or die('ODBC Error:: '.odbc_error().' :: '.odbc_errormsg().' :: '.$virtual_dsn);
if ($connection){ echo "Good <p>" }
# query the users table for name and surname
$query = "SELECT id,barcode FROM Asset";
# perform the query
$result = odbc_exec($connection, $query);
# fetch the data from the database
while(odbc_fetch_row($result) ){
$id = odbc_result($result, 1);
$bcd = odbc_result($result, 2);
print("id=$id barcode $bcd<br>"); $x+=1;
}
# close the connection
odbc_close($connection);
?>