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.