Heim  >  Artikel  >  Backend-Entwicklung  >  pdo和ODBC来连接SQL Server_PHP教程

pdo和ODBC来连接SQL Server_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:04:19861Durchsuche

pdo和ODBC来连接SQL Server

下载驱动程序,我下载的是2.0的,下载后安装释放程序,里面有以下文件:

php教程_pdo_sqlsrv_52_nts.dll

php_pdo_sqlsrv_52_ts.dll

php_pdo_sqlsrv_53_nts_vc6.dll

php_pdo_sqlsrv_53_nts_vc9.dll

php_pdo_sqlsrv_53_ts_vc6.dll

php_pdo_sqlsrv_53_ts_vc9.dll

php_sqlsrv_52_nts.dll

php_sqlsrv_52_ts.dll

php_sqlsrv_53_nts_vc6.dll

php_sqlsrv_53_nts_vc9.dll

php_sqlsrv_53_ts_vc6.dll

php_sqlsrv_53_ts_vc9.dll

SQLServerDriverForPHP.chm(手册,英文够好的话,可以看看,嘿嘿)

SQLServerDriverForPHP_License.rtf

SQLServerDriverForPHP_Readme.htm(自述文件)

 

下面是自述文件里的内容,我翻译一下:

 

驱动程序文件
 PHP 版本
 线程安全性
 用于PHP .dll
 
php_sqlsrv_53_nts_vc6.dll

php_pdo_sqlsrv_53_nts_vc6.dll
 5.3
 no
 php5.dll
 
php_sqlsrv_53_nts_vc9.dll

php_pdo_sqlsrv_53_nts_vc9.dll
 5.3
 no
 php5.dll
 
php_sqlsrv_53_ts_vc6.dll

php_pdo_sqlsrv_53_ts_vc6.dll
 5.3
 yes
 php5ts.dll
 
php_sqlsrv_53_ts_vc9.dll

php_pdo_sqlsrv_53_ts_vc9.dll
 5.3
 yes
 php5ts.dll
 
php_sqlsrv_52_nts.dll

php_pdo_sqlsrv_52_nts.dll
 5.2
 no
 php5.dll
 
php_sqlsrv_52_ts.dll

php_pdo_sqlsrv_52_ts.dll
 5.2
 yes
 php5ts.dll
 

 

关于VC6和VC9的区别,还有非线程安全与线程安全

 

VC6 版本是使用 Visual Studio 6 编译器编译的,如果你是在windows下使用Apache+PHP的,请选择VC6版本。

VC9 版本是使用 Visual Studio 2008 编译器编译的,如果你是在windows下使用IIS+PHP的,请选择VC9版本。

Non Thread Safe就是非线程安全,在执行时不进行线程(Thread)安全检查;

Thread Safe 是线程安全,执行时会进行线程(Thread)安全检查,以防止有新要求就启动新线程的 CGI 执行方式而耗尽系统资源;

 


开始配置

 


我用的是APMserv 搭建的PHP环境(Apache 2.2.9+PHP 5.2.6+MySQL 5.1.28),想用线程安全的,所以选择php_sqlsrv_52_ts.dll和php_pdo_sqlsrv_52_ts.dll。

开始工作,先把文件拷贝到PHP文件夹下的ext目录下,然后在配置文件php.ini
的Extensions后面加上:

;extension=php_sqlsrv_52_ts.dll

;extension=php_pdo_sqlsrv_52_ts.dll

再重启Apache。

最后测试一下是否成功,看一下phpinfo的sqlsrv

 


如图所示这样就表示连接成功了!!开始工作喽!

 

连接数据库教程

 

使用过SQL Server的人应该都清楚,SQL Server常用的有两种认证方式,一种是本地系统账户认证(Windows Authentication ),一种是使用用户名和密码(SQL Server Authentication ),第二种认证方式必须启用SQL Server的混合模式。

 

1.Windows Authentication连接部分代码段


*/

 

$serverName = "(local)";
$connectionInfo = array("Database"=>"test","ConnectionPooling"=>false);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
    echo "连接失败!";
    die( print_r( sqlsrv_errors(), true));
}

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630856.htmlTechArticlepdo和ODBC来连接SQL Server 下载驱动程序,我下载的是2.0的,下载后安装释放程序,里面有以下文件: php教程_pdo_sqlsrv_52_nts.dll php_pdo_sqlsrv_52_...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn