About PHP Connection mssql:pdo ODBC SQL server_php Tips

Source: Internet
Author: User
Tags install php odbc mssql
There is only one php_pdo_odbc.dll.
So~ the newest and best PHP connection MSSQL method should be this:
Copy Code code as follows:

<?php
$CNX = new PDO ("Odbc:driver={sql Server}"; server=127.0.0.1;database=test; ", ' sa ', ' asd123 ');
Var_dump ($CNX);
$a = $cnx->query ("SELECT * from [user]");
Var_dump ($a);
foreach ($a as $b) {
Var_dump ($b);
}
?>


questions about PHP's inability to connect to the MSSQL database
Today configured a new server, configuration is iis+php, the results of the runtime found that PHP connection remote MSSQL database error, error code as follows:
Warning:mssql_connect (): Unable to connect to server:
Think of the past is no problem, how is it? Later went to the internet search, found an article, only to find that the original server is required to install MSSQL to use PHP to connect MSSQL, originally the new server I do not need to use MSSQL, but now there is no way, can only put it on, installed after the MSSQL will be no problem.
I was thinking, if it is on the Linux apache+php will be, it is impossible to install MSSQL Bar, oh, dizzy.
Here is an article to find.
PHP Configuration:
In the php.ini file, set the following to find
Extension=php_mssql.dll remove the semicolon from the front.
Find Extension_dir = d:\extension\
Your php.ini may not be d:\extension\.
Change to the extensions directory below the PHP installation directory Php_mssql.dll, where the path is, if you haven't moved it to another place (assuming your PHP installation path is d:\php)
Change it into extension_dir=d:\php\extensions\.
Then restart the Web server

This is easy to do, but after this setting is still not connected, the wrong message is as follows:
MS SQL Server database connection Error! Please check that the database host variable settings are correct!!!
And the host's variable settings I am over and over again, those settings are not a problem, go through the Web page, found the following clues:

Php.com Information:
I am trying to connect to SQL Server PHP
I bumped to following warning:
Warning:mssql_connect (): Unable to connect to Server:server\portal
... on line 5
On line 5 There is:
$db _connect = mssql_connect (' server\portal ', ' sa ', ' my_passwd ');
I did the following
1.enabled php_mssql.dll Extension in php.ini
2.every DLL is in proper place (System32 or PHP folder), including Ntwdblib.dll
I search Lots of profile throught Web, but no. one give me proper answer to resolve it.
After a few hour, I found the problem is caused by
Ntwdblib.dll, which version is 7.00.839, where I replaced old ntwdblib.dll with the new
Ntwdblib.dll, which version is 8.00.194, all problem are solved.
We had some, read A LOT, of problems with MSSQL under Windows 2003.
We had 2 the same windows, PHP, Php-ini, everything machines only one but connect.
Unable to connect is the error message.
Finnaly we checked the version of Ntwdblib.dll and the one distributed with PHP is 7.00 ....
And the version of the "One on" SQL Server install was 8.00 .... So we copied this one in
The PHP and Apache dir and it worked.
The problem was found, and the trouble was it ntwdblib.dll
The primary role of Ntwdblib.dll is to provide SQL Server connection services.
I used the version of PHP is 4.3.9, in the installation of its windows/system32/I found the Ntwdblib.dll file version is 2000.2.8.0, this version is supported by SQL Server 7.0, Because when you install PHP, you will overwrite all the files below DLLs to the system
directory, so when I use it to connect to SQL Server 2000, of course I will not be able to connect.
Later, I found the version of Ntwdblib.dll on a server with a normal install of SQL Server 2000 is 2000.80.2039.0, I copy this file to the past, overwriting the previous version, restart the server, everything is normal.
Add: If the database name starts with a number and you're prompted not to open it, it's easy to do it with the name of the database in brackets []
Around, such as 123bbs rewrite into [123bbs] no problem, in addition, if your database name and SQL Server in the case of a reserved word conflict will also occur, with the method of parentheses can be resolved.
Finally, the problem of PHP incorrectly connecting to SQL Server 2000 is finally solved, although it takes a long time, but the harvest is still very large, now put it out, but also let the brothers encounter the same problem less to take some detours.

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.