php PDOException SQLSTATE[HY000] [2002] 本地计算机上的连接超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31897406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:41:35  来源:igfitidea点击:

PDOException SQLSTATE[HY000] [2002] Connection timed out on my local computer

phpmysqlpdo

提问by SCAREX

Recently I've imported my code from my server but the local code can't connect to the remote mysql database.

最近我从我的服务器导入了我的代码,但是本地代码无法连接到远程 mysql 数据库。

So I have 2 questions : - Can I access to my remote databse If yes : why is my code not working ? If no : is there a way to bypass this problem ? (I don't want to make a copy of my mysql database that would run on my local computer)

所以我有 2 个问题: - 我可以访问我的远程数据库如果是:为什么我的代码不起作用?如果不是:有没有办法绕过这个问题?(我不想复制可在本地计算机上运行的 mysql 数据库)

My code : $dbh = new PDO("mysql:host={$db_host};dbname={$db_name}", $db_user, $db_pass);

我的代码: $dbh = new PDO("mysql:host={$db_host};dbname={$db_name}", $db_user, $db_pass);

My remote server is from LWS.

我的远程服务器来自 LWS。

采纳答案by Araz Jafaripur

For remote access, You should to enable remote access to your MySQL Server.
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

对于远程访问,您应该启用对 MySQL 服务器的远程访问。
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html