PHP connection to MSSQL

Source: Internet
Author: User
When you operate MSSQL in PHP, you must first determine whether the system running environment is supported. run the following statement to know [php] if (function_exists (& amp; #39; mssql_connect & amp; #39;) {echo & amp; #39; this function exists, indicating that the environment supports MSSQL & amp; #39 ;;} else {echo & amp; #39; you

When you operate MSSQL in PHP, you must first check whether the system running environment is supported and run the following statements.


[Php]
If (function_exists ('mssql _ connect ')){
Echo 'This function exists, indicating that the environment supports mssql ';
} Else {
Echo 'Your environment does not support MSSQL, please configure it in APACHE ';
}

If (function_exists ('mssql _ connect ')){
Echo 'This function exists, indicating that the environment supports mssql ';
} Else {
Echo 'Your environment does not support MSSQL, please configure it in APACHE ';
} When the PHP environment is not supported, configure the environment using the following methods:

1. open your PHP. INI configuration file and remove ";" Before extension = php_pdo_mssql.dll and extension = php_mssql.dll. try to find words related to mssql and enable them;

2. you may not have a database connected to MSSQL in your runtime environment. Therefore, you must check whether php_mssql.dll and ntwdblib in the ext directory exist in your PHP directory. DLL. some articles on the Internet say that you need to COPY the file to the WINDOWS/SYSTEM32 directory. if the file cannot be connected, try it;

3. restart APACHE. if it doesn't work, restart the entire machine (sometimes abnormal ).

After completing the above three steps, do not think it is done. you can solve PHP + MSSQL, followed by character set problems.


[Php]
Mssql_select_db ($ db_name, $ conn );
$ SQL = "INSERT INTO contacts (ID, MemberNo, Name, CustomerStateID, Ext, Phone, Mobile, email, QQ, Gender, Company, Province_ID, City_ID, Address, Postalcode) VALUES (4, 'bx4 ', 'Liu Biao', 1, '','', '000000', '', '000000', 'male ', 'huakang Insurance Agency Co., Ltd. Guangdong Branch ', 510035, '2 floor, service center building, Guangzhou Military Region, No. 5, Yuexiu district, Guangzhou ')";
$ SQL = iconv ('utf-8', 'gb2312', $ SQL); // This conversion is required. if your encoding is the same, it is fine, I have struggled on this issue for a long time.
$ Query = mssql_query ($ SQL, $ conn );

Mssql_select_db ($ db_name, $ conn );
$ SQL = "INSERT INTO contacts (ID, MemberNo, Name, CustomerStateID, Ext, Phone, Mobile, email, QQ, Gender, Company, Province_ID, City_ID, Address, Postalcode) VALUES (4, 'bx4 ', 'Liu Biao', 1, '','', '000000', '', '000000', 'male ', 'huakang Insurance Agency Co., Ltd. Guangdong Branch ', 510035, '2 floor, service center building, Guangzhou Military Region, No. 5, Yuexiu district, Guangzhou ')";
$ SQL = iconv ('utf-8', 'gb2312', $ SQL); // This conversion is required. if your encoding is the same, it is fine, I have struggled on this issue for a long time.
$ Query = mssql_query ($ SQL, $ conn); if the iconv conversion is not performed, different encodings will cause mssql_query to return false. I have used @ mssql_query ("SET NAMES UTF8 ", $ conn); converts all SQL statements.

To complete the preceding operations, you can perform database operations.

 

 

 

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.