Home > Backend Development > PHP Tutorial > About php connection mssql: pdo odbc sql server_PHP tutorial

About php connection mssql: pdo odbc sql server_PHP tutorial

WBOY
Release: 2016-07-21 15:26:41
Original
938 people have browsed it

There is only one php_pdo_odbc.dll.
so~The latest and best method of connecting to mssql with php should be like this:

Copy code The code is 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);
}
?>


About the problem that PHP cannot connect to the MSSQL database
I configured a new server today. The configuration is IIS+php. As a result, when running, I found an error in connecting php 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 am thinking, what will happen if it is apache+php on Linux? It is impossible to install mssql, haha, I am dizzy.
The following is an article 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. The ini may not be d:extension
but should be changed 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 extension_dir=d:phpextensions
Then restart the web server

This is easy to do, but after making such settings, you still can’t connect. The error message is as follows:
MS SQL Server database connection error! Please check whether the database host variable settings are correct!!!
I checked the host variable settings over and over again, and there was no problem with those settings. I searched the web and found 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 and caused trouble. The main function of ntwdblib.dll
ntwdblib.dll 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 of the installation PHP will overwrite all files under dlls 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, 123bbs is rewritten as [ 123bbs] There is no 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.
Finally, the problem of PHP being unable to correctly connect to sql server 2000 was finally solved. Although it took most of the day, the harvest was still great. Posting it now will also save time for brothers who encounter the same problem. detour.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323938.htmlTechArticleThere is only one php_pdo_odbc.dll. so~The latest and best method of connecting to mssql with php should be like this: Copy the code as follows: ?php $cnx = new PDO("odbc:Driver={SQL Server};Server=127.0.0.1;Da...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template