PHP 5.4 Successfully connected to SQL Server 2005; sqlsrv30.exe;php_sqlsrv_54_ts.dll
1. Download the DLL provided by Microsoft
Address: http://www.microsoft.com/en-us/download/details.aspx?id=20098
I under the SQLSRV30.EXE, this EXE is a self-extracting file, downloaded after double-click on the path to extract will get a bunch of DLLs and documentation.
2, the corresponding PHP version of the DLL file copy to the PHP ext directory
TS refers to thread safety (ThreadSafe), NTS refers to the thread is unsafe, depending on the version of PHP installed to choose, if not sure, try it separately;
I use the php5.4, will php_sqlsrv_ _ts.dllCopy to the ext directory,
Example: D:\Program files\php 5.4\ext
3. Modify the php.ini file
Add one line: Extension=php_sqlsrv_54_ts.dll
Modify one line: Mssql.secure_connection = Off to On
4. Restart Apache
5. Configuring MS SQL Server2005
A. Open SQL Server Configuration Manager: SQL Server Config Manager, open the Protocol;
B, enable "Named Pipes" and "TCP/IP", the default is disabled;
C, right click on "TCP/IP", select "Properties", select "IP address", "Allip" under "TCP dynamic port" after filling 1433;
D. Restart SQL Server.
Note: Remember to turn on SA login.
6. Install Microsoft SQL Server Native Client.msi
Install Microsoft SQL Server Native Client.msi, sub-X64 and X86 according to your system on the machine where the PHP server is located.
Http://www.softpedia.com/get/Internet/Servers/Server-Tools/SQL-Server-Native-Client.shtml
This tool does not support XP system Oh, so XP to use PHP5.3 Bar ~
7. PHP Code
<?
/* Connect to the database, the 5.4 function is no longer mssql_connect: */
$conInfo =array (' Database ' = ' osbst ', ' UID ' = ' sa ', ' PWD ' = ' 123456 ');
$conn =sqlsrv_connect (' 192.168.1.208 ', $conInfo);
/* Determine if the connection is successful or not: */
if ($conn = = False)
{
Die (Print_r (Sqlsrv_errors (), true));
}
Else
{
Echo ("yes<br>");
}
$table _name = ' table_name ';
/* If your fork's database table name is Chinese, remember to add this sentence: */
$table _name = iconv (' UTF-8 ', ' GB2312 ', ' The Chinese table name of the fork ');
/*query statement: */
$rs =sqlsrv_query ($conn, "select * from". $table _name);
if ($rs = = False)
{
Echo ("false<br>");
}
Else
{
while ($row = Sqlsrv_fetch_array ($rs))
{
Print_r ($row);
}
Sqlsrv_free_stmt ($RS);
Sqlsrv_close ($conn);
}
?>
PHP 5.4 Successfully connected to SQL Server 2005