简体   繁体   English

使用在线PHP文件设置对数据库的本地调用-连接时出现问题

[英]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. 试图弄清楚如何使用在线PHP文件连接到本地SQL Server。 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. 警告:mysql_connect()[function.mysql-connect]:[2002]无法建立连接,因为目标机器主动拒绝了它。 (trying to connect via tcp://localhost:xxxx) in E:\\web\\example.com\\uploads\\readDB.php on line 8 (尝试通过tcp:// localhost:xxxx连接)在第8行的E:\\ web \\ example.com \\ uploads \\ readDB.php中

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. 特别是在尝试指定是否以及在何处进行与PC的连接,然后再使用任何相关密码与数据库的连接时,遇到了麻烦。

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. 我的服务器在本地运行(SQL Server Studio Management 2012),我正在尝试从表TradingAccount连接到其特定的数据库ACME。

Can someone show me how to connect to this local table successfully with PHP? 有人可以告诉我如何使用PHP成功连接到此本地表吗? I use Windows Authentication at the moment when I run the server as well, in case that matters. 在运行服务器的同时,我也会使用Windows身份验证,以防万一。

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. 我一直找不到任何有用的资源,而且我也只使用PHP连接到在线数据库,以前在本地没有任何连接。

Your Problem is in this line: 您的问题在此行中:

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

You wrote the_sql_server_name\\SQLEXPRESS there. 您在the_sql_server_name\\SQLEXPRESS编写了the_sql_server_name\\SQLEXPRESS 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 . 有关更多信息,请访问PHP手册条目mysql_connect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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