doujin4031 2016-07-15 12:47
浏览 47
已采纳

PHP连接到MS SQL数据库

I have a website locally hosted on my computer. My server is using PHP 5.6.21. I am trying to connect to a SQL Database on another computer Microsoft SQL Server 2000.

I have installed the PHP extensions, PHP_sqlsrv_56_ts and PHP_sqlsrv_56_nts. I have enabled them in the php.ini: extension=php_sqlsrv_56_nts.dll extension=php_sqlsrv_56_ts.dll

I have tried to connect using this:

<?php
$serverName = "serverName\sqlexpress, 1542"; //serverName\instanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$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));
}
?>

And I tried using this:

<?php 

$connection_string = 'DRIVER={SQL Server};SERVER=<Hector\SQLEXPRESS>;DATABASE=tempdb'; 
$user = 'sqltestclient';
$pass = 'paSSword';
$connection = odbc_connect( $connection_string, $user, $pass ) or die("Unable to connect to server");
echo $connection.' '.$user.' '.$pass;
?>

But neither work, the top wont load the page and the bottom just sasys unable to connect.

Im not sure what Im doing wrong

  • 写回答

2条回答 默认 最新

  • doumi1884 2016-07-26 13:43
    关注

    I was able to solve my problem using the information from this link. http://www.techrepublic.com/article/access-microsoft-sql-server-2000-using-php/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭