PHP5.3.X connecting to MSSQL database _ PHP Tutorial

Source: Internet
Author: User
Tags sql server driver
PHP5.3.X connects to the MSSQL database. In windows, versions later than PHP5.3 do not support mssql extension, so if you need to communicate with sqlserver, you need to go to msdn. microsoft. comen-ussqlserverff657782.aspx under the windows system, PHP5.3 or above version does not support mssql extension, so if you need to communicate with SQL server to http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspxthe SQL Server Driver for PHP. This is a self-extracting file. after decompression, you will get the following files:

Php_sqlsrv_52_nts_vc6.dll

Php_sqlsrv_52_ts_vc6.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

Php_sqlsrv_license.rtf

SQLServerDriverForPHP. chm

SQLServerDriverForPHP_Readme.htm


Indicates the 5.2.X and 5.3.X versions of PHP, indicates the safety of PHP, ts indicates the thread security, vc6 indicates that Apache is used as the Web Server, and vc9 indicates that IIS is used as the Web Server.


According to your configuration, copy the corresponding DLL file to the ext folder in the php installation directory. Next, open php. ini and add the following statements to open php_sqlsrv and php_pdo_sqlsrv extensions:
-------------------
[PHP_PDO_SQLSRV]
Extension = php_pdo_sqlsrv_53_ts_vc6.dll
[PHP_SQLSRV]
Extension = php_sqlsrv_53_ts_vc6.dll
-----------------

53 indicates php5.3. if your PHP version is 5.2, change it to 52. if your PHP version is thread-safe, the PHP installation directory should contain a php5ts. dll, which corresponds to the two statements here. if it is php5cnt. dll, then the above statement should be:
----------------------
[PHP_PDO_SQLSRV]
Extension = php_pdo_sqlsrv_53_nts_vc6.dll
[PHP_SQLSRV]
Extension = php_sqlsrv_53_nts_vc6.dll
------------------

The compressed package contains dll files of various versions. you can check the files carefully.

After enabling the extension, restart apache, so that you can connect to sqlserver, but there is another point to note, if you do not install Microsoft SQL Server 2008 R2 Native Client, you must go to the http://msdn.microsoft.com/en-us/library/cc296170 (SQL .90 ). aspx download and installation, because Microsoft's extension package requires this support.

After everything is done, you can write php code. if you download The SQL Server Driver for PHP, there is a help document in The decompressed folder, you can easily find an example. here, the webmaster will introduce a simple example:
// Name of the locally tested Service
$ ServerName = "(127.0.0.1 )";
// Use SQL server for authentication. the parameters are in the form of an array. one request is a user name, password, and database name.
// If you are using windows Authentication, you can remove the user name and password
$ ConnectionInfo = array ("UID" => "root ",
"PWD" => "root2010 ″,
"Database" => "master ");

$ Conn = sqlsrv_connect ($ serverName, $ connectionInfo );

If ($ conn)
{
Echo "Connection established. \ n ";
}
Else
{
Echo "Connection cocould not be established. \ n ";
Die (print_r (sqlsrv_errors (), true ));
}
?>

If the connection fails, restart SQL server and try again.


From Chris Mao's column

Server communication needs to go to http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx...

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.