PHP connection MSSQL database exception emergency-php Tutorial

Source: Internet
Author: User
PHP connection MSSQL database error urgent I use mysql_connect () to connect to MySql database normally, but cannot connect with mssql_connect (), prompt cannot connect to the database. PDO connections cannot be connected. Previously, I used a C ++ program to connect to my SQLSERVER. everything is normal. what is the reason? please explain, I 've hung up my PDO connection and error code to help you solve the problem. thank you very much for connecting $ d PHP to the MSSQL database.
I use mysql_connect () to connect to the MySql database normally, but mssql_connect () cannot be connected, prompting that the database cannot be connected. PDO connections cannot be connected. Previously, I used a program in C ++ to connect to my SQL server. what is the reason? please explain. I am in a hurry.

I have hung up my PDO connection and error code to help you solve the problem. thank you very much.
$ Dbh = new PDO ('mssql: host = localhost; dbname = mydata', 'sa ',' ***** '); // The password is hidden.
This code cannot be connected. the error message is:
'Sqlstate [01002] Unable to connect: SQL Server is unavailable or does not exist. Access denied. (severity 9 )'

------ Solution --------------------
Discussion

Reference:

SQL Server Configuration Manager

Thank you. the connection is successful.
I found the problem. when mssql_connect is used, the servername cannot be localhost or 127.0.0.1. if this is used, the server cannot be found. just change it to the computer name. I am dizzy, and I am delayed for a long time.

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.