PDO and ODBC to connect to SQL Server

Source: Internet
Author: User
Tags odbc vc9

Download the driver, I downloaded is 2.0, download after the installation release program, which has the following files:

PHP Tutorials _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 (manual, English good enough, you can see, hehe)

Sqlserverdriverforphp_license.rtf

Sqlserverdriverforphp_readme.htm (Readme file)

Here is the content in the Readme file, I translate:

Driver files
PHP version
Thread Security
for 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

About the difference between VC6 and VC9, as well as thread-safe and threading-safe

The VC6 version is compiled using the Visual Studio 6 compiler, and if you are using apache+php under Windows, select the VC6 version.

The VC9 version is compiled using the Visual Studio 2008 compiler, and if you are using iis+php under Windows, select the VC9 version.

Non thread safety is not thread safe and does not perform thread security checks at execution time;

Thread safe is threaded, and thread safety checks are carried out to prevent new requirements from running out of system resources in the form of CGI execution that starts a new thread;


Start configuration


I use the Apmserv built PHP environment (Apache 2.2.9+php 5.2.6+mysql 5.1.28), want to use thread-safe, so choose Php_sqlsrv_52_ts.dll and Php_pdo_sqlsrv_52_ Ts.dll.

To start work, first copy the file to the Ext directory under the PHP folder, and then in the configuration file php.ini
Extensions followed by:

; Extension=php_sqlsrv_52_ts.dll

; Extension=php_pdo_sqlsrv_52_ts.dll

Restart Apache again.

The final test is successful, look at the phpinfo sqlsrv


As shown in the picture, this means the connection is successful!! Get to work!

Connecting to a database tutorial

People who have used SQL Server should be aware that SQL Server typically has two authentication methods, one is the local System account authentication (Windows authentication) and the other is the use of user names and passwords (SQL Server Authentication , the second authentication method must enable mixed mode for SQL Server.

1.Windows Authentication Connection Section code snippet


*/

The code is as follows Copy Code
$serverName = "(local)";
$connectionInfo = Array ("Database" => "Test", "connectionpooling" =>false);
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn = = False)
{
echo "Connection failed! ";
Die (Print_r (Sqlsrv_errors (), true));
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.