Home > Backend Development > PHP Tutorial > pdo and ODBC to connect to SQL Server_PHP tutorial

pdo and ODBC to connect to SQL Server_PHP tutorial

WBOY
Release: 2016-07-13 17:04:19
Original
906 people have browsed it

pdo and ODBC to connect to SQL Server

Download the driver. I downloaded the 2.0 version. After downloading, install the release program, which contains the following files:

php tutorial_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, if your English is good enough, you can read it, hehe)

SQLServerDriverForPHP_License.rtf

SQLServerDriverForPHP_Readme.htm (readme file)

The following is the content in the readme file, let me translate it:

Driver file
PHP version
Thread safety
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

Regarding the difference between VC6 and VC9, there are also non-thread safety and thread safety

The VC6 version is compiled using the Visual Studio 6 compiler. If you are using Apache+PHP under Windows, please select the VC6 version.

The VC9 version is compiled using the Visual Studio 2008 compiler. If you are using IIS+PHP under Windows, please select the VC9 version.

Non Thread Safe means non-thread safety, no thread (Thread) safety check is performed during execution;

Thread Safe is thread safe. Thread safety checks will be performed during execution to prevent CGI execution from starting new threads when new requirements arise and exhausting system resources;


Start configuration


I use the PHP environment built by APMserv (Apache 2.2.9+PHP 5.2.6+MySQL 5.1.28). I want to use thread safety, so I choose php_sqlsrv_52_ts.dll and php_pdo_sqlsrv_52_ts.dll.

To start working, first copy the file to the ext directory under the PHP folder, and then configure the file php.ini
Add after Extensions:

;extension=php_sqlsrv_52_ts.dll

;extension=php_pdo_sqlsrv_52_ts.dll

Restart Apache again.

Finally, to test whether it is successful, take a look at phpinfo’s sqlsrv


As shown in the picture, this means the connection is successful! ! Let’s get to work!

Tutorial on connecting to database

Anyone who has used SQL Server should know that there are two commonly used authentication methods in SQL Server, one is local system account authentication (Windows Authentication), the other is using user name and password (SQL Server Authentication), and the second is This authentication method must enable the mixed mode of SQL Server.

1.Windows Authentication connection part code snippet


*/

$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));
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630856.htmlTechArticlepdo and ODBC to connect to SQL Server. Download the driver. I downloaded the 2.0 version. After downloading, install the release program. There are the following files inside: php tutorial_pdo_sqlsrv_52_nts.dll php_pdo_sqlsrv_52_...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template