php 连接 SQL Server 2008
2016-10-03 14:22
369 查看
PHP自带的MSSQL扩展php_mssql.dll是给SQL Server 2000用的,SQL Server 2000+的版本用微软为PHP提供的第三方扩展:Microsoft SQL Server PHP 驱动程序,URL是:https://msdn.microsoft.com/library/dn865013.aspx ,下载版本参照以下(注意:如果是3.1+版本还需要下载安装ODBC):
Version support for PHP is as follows
Version 4.0 supports PHP 7.0+
Version 3.2 supports PHP 5.6, 5.5, and 5.4
Version 3.1 supports PHP 5.5 and 5.4
Version 3.0 supports PHP 5.4.
For more detail and for supported operating systems, see System
Requirements (Microsoft Drivers for PHP for SQL Server) .
An Internet Information Services (IIS) Web server is required
Version 4.0 requires Microsoft
ODBC Driver 11 or Microsoft
ODBC Driver 13.
Versions 3.2 and 3.1 of the driver require Microsoft ODBC Driver 11 (or higher). You can download the Microsoft
ODBC Driver 11 here.
Version 3.0 requires the x86 version of Microsoft SQL Server 2012 Native Client.
比如下载SQLSRV31.EXE文件双击解压得到N个*.dll文件,根据php安装目录包含的类似“php5ts.dll”来使用对应的*.ts.dll或*.nts.dll,参考如下URL:https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx 。
配置:
把 php_sqlsrv_55_ts.dll 和 php_pdo_sqlsrv_55_ts.dll 一起拷贝到php安装目录的扩展目录(ext)下,配置php.ini文件:增加以下两行:
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
重启相关服务后用phpinfo测试是否安装成功。
连接数据库测试:
<?php
$serverName = "MS-201703.....GD\SQLEX....."; //服务器名称,在 sql server management studio 的登录界面查看
$uid = "sa"; //数据库用户名
$pwd = "123"; //数据库密码
$db = "cart"; // 数据库名
$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>$db);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false) {
echo "连接失败!";
die( print_r( sqlsrv_errors(), true));
}
//执行有结果集的SQL语句
$query = sqlsrv_query($conn, "select top 1 * from tb_goods");
$row = sqlsrv_fetch_array($query) ;
print_r($row);
?>
Version support for PHP is as follows
Version 4.0 supports PHP 7.0+
Version 3.2 supports PHP 5.6, 5.5, and 5.4
Version 3.1 supports PHP 5.5 and 5.4
Version 3.0 supports PHP 5.4.
For more detail and for supported operating systems, see System
Requirements (Microsoft Drivers for PHP for SQL Server) .
An Internet Information Services (IIS) Web server is required
Version 4.0 requires Microsoft
ODBC Driver 11 or Microsoft
ODBC Driver 13.
Versions 3.2 and 3.1 of the driver require Microsoft ODBC Driver 11 (or higher). You can download the Microsoft
ODBC Driver 11 here.
Version 3.0 requires the x86 version of Microsoft SQL Server 2012 Native Client.
比如下载SQLSRV31.EXE文件双击解压得到N个*.dll文件,根据php安装目录包含的类似“php5ts.dll”来使用对应的*.ts.dll或*.nts.dll,参考如下URL:https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx 。
配置:
把 php_sqlsrv_55_ts.dll 和 php_pdo_sqlsrv_55_ts.dll 一起拷贝到php安装目录的扩展目录(ext)下,配置php.ini文件:增加以下两行:
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
重启相关服务后用phpinfo测试是否安装成功。
连接数据库测试:
<?php
$serverName = "MS-201703.....GD\SQLEX....."; //服务器名称,在 sql server management studio 的登录界面查看
$uid = "sa"; //数据库用户名
$pwd = "123"; //数据库密码
$db = "cart"; // 数据库名
$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>$db);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false) {
echo "连接失败!";
die( print_r( sqlsrv_errors(), true));
}
//执行有结果集的SQL语句
$query = sqlsrv_query($conn, "select top 1 * from tb_goods");
$row = sqlsrv_fetch_array($query) ;
print_r($row);
?>
相关文章推荐
- Linux下php连接sql server 2008
- php连接sql server 2008数据库
- php连接sql server 2008案例
- PHP连接SQL Server 2005 和 SQL Server 2008【草案】
- [置顶] PHP连接SQL Server 2008
- PHP5.6.15连接Sql Server 2008配置方案
- Linux下php连接sql server 2008
- PHP5.4 连接 SQL SERVER 2008
- PHP5.6.15连接Sql Server 2008配置方案
- 关于PHP5.6连接SQL Server 2008 R2数据库驱动及一些问题
- PHP连接SQL Server 2005 和 SQL Server 2008【草案】
- PHP5.6.15连接Sql Server 2008配置方案
- 64位IIS7下的PHP 5.4配置及如何连接SQL Server 2008
- PHP 5.3连接sql server 2008 R2
- 64位IIS7下的PHP 5.4配置及如何连接SQL Server 2008
- PHP连接SQL Server 2005 和 SQL Server 2008
- php 连接 SQL Server 2008
- 使用JDBC连接SQL SERVER 2008的方法
- SQL SERVER 2008 EXPRESS版本远程连接(tcp/ip)
- sql server 2008 64位连接sql 2000服务器出错解决办法