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

Jul 21, 2016 pm 03:26 PM
mssql odbc pdo php server sql about connect

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

See all articles