There is only one php_pdo_odbc.dll.
so~The latest and best php method to connect to mssql should be like this:
Copy the code 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($a);
foreach ($a as $b) {
var_dump($b);
}
?>
About the problem that PHP cannot connect to the MSSQL database
A new server was configured today, and the configuration is IIS +php, when running, it was found that there was an error when PHP connected to the remote mssql database. The error code is as follows:
Warning: mssql_connect(): Unable to connect to server:
Think about it, it was no problem before, what happened? Later, I searched online and found an article, only to find out that the server needs to install mssql in order to use php to connect to mssql. Originally, I didn’t need to use mssql on the new server, but now I have no choice but to install it. Yes, after installing mssql there will be no problem.
I was thinking, what would happen if it is apache+php on Linux? It is impossible to install mssql, haha, I am dizzy.
The following is an article I found.
php configuration:
Set as follows in the php.ini file, find
;extension=php_mssql.dll and remove the semicolon in front of it
Find extension_dir = d:extension
Your php.ini may not contain d:extension
Change it to The path of php_mssql.dll under the extensions directory under the php installation directory. If you have not moved it to another place (assuming that your php installation path is d:php)
Change it to extensi
Then restart the web server
This is easy to do, but after completing such settings, it still cannot be connected. The error message is as follows:
MS SQL Server database connection error! Please check whether the database host variable settings are correct!!!
And the host variable settings I checked over and over again, and there was no problem with those settings. After browsing the web, I found the following clues:
php.com information:
I am trying to connect to SQL Server 2000 from PHP
I bumped to following warning:
Warning: mssql_connect(): Unable to connect to server: SERVERPortal
..... on line 5
on line 5 there is:
$db_connect = mssql_connect('SERVERPortal', '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 hours ,I found the problem was 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 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 could 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, the trouble was ntwdblib.dll
ntwdblib.dll’s main function is to provide sql server connection service.
The PHP version I use is 4.3.9. In the windows/system32/ of the server where it is installed, I found that the version of the ntwdblib.dll file is 2000.2.8.0. This version supports SQL Server 7.0, because when installing PHP All files under dlls will be overwritten into the system directory, so when I use it to connect to sql server 2000, of course I will be unable to connect.
Later, I found out that the version of ntwdblib.dll was 2000.80.2039.0 on a server where SQL Server 2000 was installed normally. I copied this file to overwrite the previous version. After restarting the server, everything was normal.
Supplement: If the database name starts with a number, it will also prompt that it cannot be opened. At this time, it is very simple. Enclose the name of the database in square brackets [ ]
and it will be done. For example, if 123bbs is rewritten as [123bbs], it will not work. Problem. In addition, this situation will also occur if your database name conflicts with the reserved words in SQL Server. You can also solve it by using square brackets.
In the end, the problem of PHP being unable to connect to SQL Server 2000 correctly was finally solved. Although it took most of a day, the harvest was still great. Posting it now will save brothers who encounter the same problem from taking some detours.
The above introduces the PHP connection to mssql. About PHP connection to mssql: pdo odbc sql server, including the content of PHP connection to mssql. I hope it will be helpful to friends who are interested in PHP tutorials.