在Mac上连接到Microsoft SQL Server PHP

时间:2015-01-26 09:34:06

标签: php sql-server macos

我有一张优胜美地的Macbook。我从苹果商店下载应用程序以尝试运行PHP代码。我想连接到Microsoft SQL Server,这是代码:

$serverName = "astidbs";
$connectionInfo = array( "Database"=>"generale1", "UID"=>"xxxx", "PWD"=>"xxxx");
$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));
}

这是错误:

Fatal error: Call to undefined function sqlsrv_connect() in /private/var/folders/t5/zjgg2nv149x48bqqdhvnllcw0000gn/T/com.kukosk.PHP-Code-Tester/PHP_Code_Tester_tempfile.php on line 5

我无法理解这是否是应用程序问题所以我在在线测试仪上尝试了代码,但它也不起作用。错误是相同的,但没有路径。似乎没有指定调用的lib,所以我在Google上搜索了如何安装,但我无法解决问题。有人有解决方案吗?

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

<?php
$myServer = "astidbs";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "examples"; 

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB"); 

//close the connection
mssql_close($dbhandle);
?>