将php连接到MS SQL Server 2008

时间:2015-08-06 05:57:46

标签: php sql sql-server-2008

我需要一个php和MS SQL的连接脚本: 在尝试以下但它不起作用

$server = 'MVEKELDG156\SQLEXPRESS'; $username   = 'EDUC.PWV.GOV.ZA\Mveke.L';    
$password   = 'password@'; $database    = 'SAMS_EMIS_Warehouses';       
if(!mysql_connect($server, $username, $password)) { exit('Error: could not 
establish database connection'); } if(!mysql_select_db($database)) { 
exit('Error: could not select the database'); }

2 个答案:

答案 0 :(得分:1)

通过将extension=php_mssql.dll添加到php.ini来启用MSSQL扩展程序。

要使这些函数正常工作,您必须使用--with-mssql [= DIR]编译PHP,其中DIR是FreeTDS安装前缀。并且应该使用--enable-msdblib编译FreeTDS。

更多参考资料:

Installation

<强> How to use PHP to connect to sql server

<强> Connecting to an SQL Server Database with PHP

答案 1 :(得分:0)

检查

$myServer = "localhost";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "SAMS_EMIS_Warehouses";

//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

来源How to connect to MS SQL Server database