简体   繁体   中英

Setting up a local call to DB with an online PHP file - trouble connecting

Trying to figure out how to connect to a local SQL Server with an online PHP file. However I am getting connection errors.

Warning: mysql_connect() [function.mysql-connect]: [2002] No connection could be made because the target machine actively refused it. (trying to connect via tcp://localhost:xxxx) in E:\\web\\example.com\\uploads\\readDB.php on line 8

In particular I am having trouble trying to specify if, and where, I do the connection to the PC and then to the database with any associated passwords.

My current connection looks like this

 mysql_connect("localhost","the_sql_server_name\SQLEXPRESS","mysql"); 
 mysql_select_db("ACME") or die(mysql_error()); 
 $data = mysql_query("SELECT * FROM TradingAccount") 
 or die(mysql_error()); 

My server is run locally (sql server studio management 2012), and I am trying to connect to its specific DB called ACME, from the table TradingAccount.

Can someone show me how to connect to this local table successfully with PHP? I use Windows Authentication at the moment when I run the server as well, in case that matters.

I haven't been able to find any useful resources, and I have only ever used PHP to connect to online DB's as well, nothing locally before.

Your Problem is in this line:

mysql_connect("localhost","the_sql_server_name\SQLEXPRESS","mysql"); 

You wrote the_sql_server_name\\SQLEXPRESS there. I don't understand why. The syntax of the method is:

mysql_connect("hostname", "username", "password");

For more information, visit the PHP manual entry for mysql_connect .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM