PHP Connection MSSQL Common all the problems

Source: Internet
Author: User
Tags mssql mysql functions php and mysql php script

PHP Ntwdblib.dll when connecting MSSQL
PHP connection MSSQL Configuration and PHP code demo collection
If PHP and MySQL link is implemented, PHP and MSSQL link is actually very simple;
Support for MSSQL local links and remote links, with local links as an example:
MS SQL Server 2005 is installed on the machine;
Configure the system before connecting:
1. Check the file Php5.2.5\ntwdblib.dll by default there is one, cannot connect and replace.
Download the correct version of Ntwdblib.dll (2000.80.194.0), Address:


2. Configure PHP
A. Open php.in to remove the extension=php_mssql.dll annotation symbol.
B. Open php.in to change mssql.secure_connection = off to ON.
C, copy the Php_mssql.dll to the php.in extension_dir the specified directory or the system system32 directory.
(Php_mssql.dll is available in the ZIP installation package for PHP).

You will need to restart Apache after the above steps have been completed.
Note: In practice, it is found that the machine must be restarted, not just IIS, if it is manually installed through PHP compressed files to IIS.
3. Configure SQL Server
A. Running SQL Server Configuration Manager: SQL Server Config Manager, opening protocol protocols
B. Allow Named pipes "Named Pipes" and "TCP/IP"
C. Right-click on "TCP/IP" to open the Properties property tag "addresses"
D. Filling in TCP dynamic port "TCP Ports" 1433
E. Restarting SQL Server
 
-----------------------------------------------------------------------------------------
------
4. Connect MS SQL Server 2005 using the following method:
The code is as follows:
<?php
Link Database
$conn =mssql_connect (' localhost ', ' sa ', ' 123456 ');
mssql_select_db (' Gu_dde ', $conn);
Query statement
$Query = "SELECT * from Dde_top";
$AdminResult =mssql_query ($Query);
Output results
$Num =mssql_num_rows ($AdminResult);
for ($i =0; $i < $Num; $i + +)
{$Row =mssql_fetch_array ($AdminResult);
Echo ($Row [1]);
Echo ("<br/>");
}?>
You can see that these functions and MySQL functions are corresponding to the use of very convenient!
-----------------------------------------------------------------------
5.FAQ FAQ:
1 Error:
Fatal error:call to undefined function mssql_connect ()
Solve:
Using the MSSQL_ series functions
To use both of these, you need to set the php.ini:
(1) Allow DCOM, need to be in php.ini; Com.allow_dcom=true before the semicolon ";" Remove.
(2) The use of MSSQL extension, need php.ini; Extension=php_mssql.dll before the semicolon ";" Remove. Key
(3) Confirm that Extension_dir is the correct path, take this machine as an example: Extension_dir = "C:\AppServ\php5\ext".
(4) If the machine error is still not found C:\AppServ\php5\ext\php_mssql.dll but clearly exists this file.
Workaround: Copy the Php_mssql.dll,ntwdblib.dll to the system directory \system32 to restart the test.
(Note: The above two DLL files are not in the same directory, my C:\appserv\php5\ext\php_mssql.dll;c:\appserv
\php5\ntwdblib.dll)
Also, remember to restart the server after you set it up well.
6. Other issues:
If PHP Apache SQL Server2000 are on the same machine, access is basically no problem.
If the SQL Server2000 and PHP machines are separate, you need to verify that the machine name of the machine where the ping SQL Server is located can pass, such as
To modify the Hosts file under the \System32\Drivers\Etc of the PHP machine, adding the machine IP of the machine where SQL Server is located
The machine name of the machine where SQL Server resides.
If you are still unable to access it, you need to verify that the machine on which PHP is located has installation MDAC. or simply install the SQL Server client
All right.


The local computer installed WAMP5, connected to the MySQL database everything is OK, but the connection to the local SQL Server2005 prompt Fatal
Error:call to undefined function mssql_connect () in. After two days of research, it turns out that I made a mentally retarded mistake.
Mistakenly, I modified not wamp loaded php.ini file, because Wamp loaded is D:\wamp\Apache2\bin\php.ini, and I
The change is D:\wamp\php\php.ini.

The following is a detailed description of the configuration process:

First, the correct installation of WAMP5, (I installed in D:\wamp);

Second, test the phpinfo.php file, and carefully look at the loaded php.ini file,

Loaded Configuration Filed:\wamp\apache2\bin\php.ini
Note: The load is D:\wamp\Apache2\bin\php.ini, so modify; Extension=php_mssql.dll don't make a mistake.

Three, open the D:\wamp\Apache2\bin\php.ini, set up two places: that is to remove; Extension=php_mssql.dll before the ";"
, then Set mssql.secure_connection = On

Iv. Check the Ntwdblib.dll version in d:/wamp/php/ext/(version 2000.2.8.0 supports SQL Server2000, version
2000.80.194.0 supports SQL Server2005).

extension_dird:/wamp/php/ext/d:/wamp/php/ext/
Note: Ntwdblib.dll and C:\system32 in d:/wamp/php/ext/require a replacement for the Ntwdblib.dll version below.

Finally restart the WAMP5 service to access my local computer SQL Server2005.

1, database connection failure problem, prompt Fatal error:call to undefined function mssql_connect () in.

To install WAMP5 (i installed in D:\wamp), the server is connected to my SQL database by default, so you want to connect to SQL
Server2005 database, the php.ini must be modified. Extension=php_mssql.dll ";" Before setting
Mssql.secure_connection = on. Then check the Ntwdblib.dll version in d:/wamp/php/ext/(version
2000.2.8.0 supports SQL Server2000, version 2000.80.194.0 supports SQL Server2005). When you're done, remember to restart the entire
WAMP5.

2, PHP page query SQL Server2005 data, Chinese display garbled.

This is because SQL Server2005 defaults to support gb2312 page encoding, and the php.ini configuration is inconsistent with the. php page encoding.
So modify two places: one is php.ini modified to Default_charset = "gb2312"; PHP page Encoding Method modified
can come, namely <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>. Note
Mysql database supports both GB2312 encoding and UTF-8 encoding)

3. Jquery.js is placed in the Inc folder under the root directory, but the PHP page cannot be referenced.

Web pages using jquery technology do not jump to the page to achieve background database interaction, must refer to jquery.js. The notation is <script.
Type= "Text/javascript" src= "/inc/jquery.js" ></script>

4, PHP page using header ("location:shopping_car.php") to direct the page error, warning:cannot modify
Header information-headers already sent by.

Cause: The Setcookie function must be sent before any data is output to the browser.

Solution: The head of the front set Ob_start (); Open buffer, and tail ob_end_flush ();//output all content to browser

5, if the PHP page encoding method is utf-8, but the page does not have <meta http-equiv= "Content-type"
Content= "text/html; Charset=utf-8 "/>. When using alert (), the Chinese language displays garbled characters.

Workaround: Be sure to specify the encoding method in the Web page as UTF-8, that is, add <meta http-equiv= "Content-type"
Content= "text/html; Charset=utf-8 "/>, because there is alert () output in Chinese to browser.


Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816
bytes

Today to use PHP code to process a 580M log file, a total of more than 2.19 million lines of records, because it is a. log file, under Windows
It is difficult to divide the file by the number of bars, so under Linux with split-l 10000 filename prefix will be the entire file by 10000
Line a split into more than 200 small files, and then use PHP to cycle through the 200 more files, but the implementation of the problem later appeared on the topic
Errors in the face:

Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816
bytes

To Baidu, the original is php.ini in the memory allocation problem, the default PHP code can apply to the maximum number of bytes of memory is
134217728 bytes, if the code execution time needs more memory, will be error, so will php.ini files in the matching
To change a bit:


Memory_limit = 128m;//changed 128M to 256M

But then, a PHP script to request more than 128M of memory space, whether you later set the Memory_limit to many
Big, there must be a time when there is a problem.

PHP Connection MSSQL Common all the problems

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.