About php connection mssql: pdoodbcsqlserver. There is only one php_pdo_odbc.dll. So ~ The latest and best php method for connecting to mssql is as follows: Copy the code as follows :? Php $ cnxnewPDO (odbc: Driver {SQLServer}; Server127.0.0.1; Da only has one php_pdo_odbc.dll.
So ~ The latest and best php method for connecting to mssql is as follows:
The 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 ($ );
Foreach ($ a as $ B ){
Var_dump ($ B );
}
?>
The problem that PHP cannot connect to the MSSQL database
Today, a new server is configured with IIS + php. when running the result, an error occurred while connecting php to the remote mssql database. the error code is as follows:
Warning: mssql_connect (): Unable to connect to server:
I think it was okay before. why? Then I went to the Internet to search and found an article, and found that the original server had to install mssql to connect to mssql using php. I didn't need mssql on the new server, but now there is no way, you can only install it. after mssql is installed, there will be no problem.
I was wondering what would happen to apache + php on linux, but it was impossible to install mssql.
The following is an article.
Php configuration:
Set the following settings in the php. ini file and find
; Extension = php_mssql.dll remove the semicolon
Find extension_dir = d: \ extension \
Your php. ini may not contain d: \ extension \
Change the path of php_mssql.dll under the extensions directory under the php installation directory. if you haven't moved it to another place (assume that your php installation path is d: \ php)
Change to extension_dir = d: \ php \ extensions \
Then restart the web server.
This is easy to do, but it cannot be connected after such a setting. the error message is as follows:
Ms SQL Server database connection error! Check whether the database host variable settings are correct !!!
I checked the host's variable settings over and over again, but those settings were none of the problem at all. I searched the webpage and found the following clues:
Php.com documents:
I am trying to connect to SQL Server 2000 from 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 was caused
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 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 but only one cocould connect.
Unable to connect was the error message.
Finnaly we checked the version of ntwdblib. dll and the one distributed with PHP was 7. 00 ....
And the version of the one on the SQL Server install was 8. 00... so we copied this one in
The php and apache dir and it worked.
The problem was found in this way, and the problem was caused by ntwdblib. dll.
Ntwdblib. dll is mainly used to provide the SQL server connection service.
My php version is 4.3.9. in the windows/system32/directory where the server is installed, I found ntwdblib. the dll file version is 2000.2.8.0. this version supports SQL server 7.0 because all the files in the dlls will overwrite the system when installing PHP.
Directory, so when I use it to connect to SQL server 2000, it will of course be unable to connect.
Later, I found ntwdblib on a server where SQL server 2000 is installed normally. the dll version is 2000.80.2039.0. I copied the file to overwrite the previous version. after the server is restarted, everything works normally.
Supplement: If the database name starts with a number, it will prompt that it cannot be opened. in this case, it is easy to use the database name in brackets [].
You can solve the problem by writing 123bbs to [123bbs]. In addition, if your database name conflicts with the reserved words in SQL server, you can solve the problem by using the brackets.
In the end, the failure of PHP to correctly connect to SQL server 2000 finally solved the problem. although it took a long time, it still gained a lot. now I have posted it, it also makes the same problem less detours.
Bytes. So ~ The latest and best php method for connecting to mssql is as follows :? Php $ cnx = new PDO ("odbc: Driver = {SQL Server}; Server = 127.0.0.1; Da...