EDIT: Sorry, I figured out what the problem was. I was editing the wrong file.
I'm (trying) to use PHP 5.3.5 to connect to my SQL SERVER 2005 but it has been nothing but trouble. On the local machine, if I use SQLCMD -S (local) -U sqlUser -P 1234 -d MyTable
it connects fine. But the following code produces an error:
<?php
$myServer = "(local)";
$myUser = "sqlUser";
$myPass = "1234";
$myDB = "MyTable";
$connectionInfo = array("Database"=> $myDB, "UID" => $myUser, "PWD" => $myPass);
//connection to the database
try{
$dbhandle = sqlsrv_connect($myServer, $connectionInfo)
or die(print_r( sqlsrv_errors(), true));
}catch(Exception $e){
echo "<pre>";
print_r($e);
echo "</pre>";
die;
}
?>
How can I get php to connect to my SQL Server?
Full Error:
Array
(
[0] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
[message] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
)
[1] => Array
(
[0] => HYT00
[SQLSTATE] => HYT00
[1] => 0
[code] => 0
[2] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired
[message] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired
)
[2] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to S开发者_如何学编程QL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
[message] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
)
)
If PHP doesn't use the same method to connect as SQLCMD you'll be seeing odd results. Doesn't PHP just use TCPIP to connect (meaning your server should be setup to listen on TCPIP as well).
Stupid mistake, I was editing the wrong file.
精彩评论