About the PHP connection mssql:pdo ODBC SQL server_php Tutorial

Source: Internet
Author: User
There is only one php_pdo_odbc.dll.
So~ the newest and best PHP connection MSSQL method should be this:
Copy CodeThe code is as follows:
$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 not connecting to MSSQL database
Today, the new server is configured, the configuration is iis+php, the results run the discovery PHP connection remote MSSQL database error, error code is as follows:
Warning:mssql_connect (): Unable to connect to server:
Think about the past is no problem, what is the matter? Later to search online, found an article, only found that the original server is required to install MSSQL to use the PHP connection MSSQL, the new server I do not need to use the MSSQL, but now there is no way, can only put it on, installed MSSQL after the no problem.
I was thinking, if it is in Linux above the apache+php will be what, it is impossible to install MSSQL, OH, dizzy.
Here is an article that I found.
PHP Configuration:
Set the following in the php.ini file 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 under the PHP installation directory under the Php_mssql.dll, where the path, if you did not move it to other places (assuming your PHP installation path is d:\php)
Change it into a extension_dir=d:\php\extensions\.
Then restart the Web server

This is easy to do, but after such a setup is still not connected, the error message is as follows:
MS SQL Server database connection Error! Check that the database host variables are set correctly!!!
And the host's variable settings I was the check again and again, those settings are not a problem, to go through the Web page, found the following clues:

Php.com Information:
I am trying to connect to SQL Server in 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 were caused by
Ntwdblib.dll, which version is 7.00.839, when I replaced old Ntwdblib.dll with the new
Ntwdblib.dll, which version is 8.00.194, all problem is solved.
We had some, read A lot, the problems with MSSQL under Windows 2003.
We had 2 the same windows, PHP, Php-ini, everything machines but only one could 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 ....
The version of the one on the SQL Server install is 8.00 .... So we copied the 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 connectivity services.
I use the PHP version is 4.3.9, in the installation of its service windows/system32/I found that the Ntwdblib.dll file version is 2000.2.8.0, this version is supported by SQL Server 7.0, Because PHP will be installed when all the files below the DLLs are overwritten to the system
directory, so when I use it to connect to SQL Server 2000, of course it will not be able to connect.
Later, I found the version of Ntwdblib.dll on a server that is normally installed on SQL Server 2000 is 2000.80.2039.0, I copy this file over, overwrite the previous version, after restarting the server, everything is OK.
Add: If the database name starts with a number, you will not be able to open it, so it is easy to do so by using the name of the database in brackets []
In the case of a 123bbs rewrite [123bbs] There is no problem, and if your database name conflicts with a reserved word in SQL Server, this will also occur, in the same way as the square brackets can be resolved.
Finally, the problem of PHP is not properly connected to SQL Server 2000 finally solved, although the cost of a large half a day, but the harvest is very large, now put it out, but also to meet the same problems of the brothers to take a few detours.

http://www.bkjia.com/PHPjc/323938.html www.bkjia.com true http://www.bkjia.com/PHPjc/323938.html techarticle there is only one php_pdo_odbc.dll. So~ the newest and best PHP connection MSSQL method should be this: Copy code code is as follows: PHP $cnx = new PDO ("Odbc:driver={sql Server}; Server=127.0.0.1;da ...

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