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 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决