Remote MySQL Connection in PHP

↘锁芯ラ 提交于 2020-01-21 12:15:07

问题


I'm beginning to migrate a software project from being a desktop application to a web application. Currently I am using a local PHP/MySQL connection that is associated with the desktop it is installed on.

I'm hoping to untangle this and am trying to create a MySQL database through my 1and1 account. I had no trouble creating a database and recorded my account information. I'd like to be able to edit this database using PHP scripts on my system. However, I haven't been able to get a working connection string going. When I run the following PHP script:

$hostname="db*********.db.1and1.com";
$database="db*********";
$username="dbo*********";
$password="*********";

$link = mysql_connect($hostname, $username, $password);

I get the following error when I run the script in my webbrowser:

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'db*********.db.1and1.com' (11001) in C:\Program Files\xampp\htdocs\Remote_MySQL\rightbid_database_initialize.php on line 74
Connection failed: Unknown MySQL server host 'db*********.db.1and1.com' (11001)

How do I get my local system to recognize the 1and1 server host? Am I structuring my connection string correctly? Is it possible to access a remote server from a locally hosted Windows PHP connection?

Thanks!


回答1:


I assume what's happening if that 1&1 are blocking any connections coming from outside of their network.

Try connecting using

mysql -h HOST -u USERNAME -p DATABASENAME

Good luck




回答2:


Make sure the MySQL server on 1and1 will accept connections from remote clients. Not just on localhost, and also make sure port 3306 is open to the server.



来源:https://stackoverflow.com/questions/13982796/remote-mysql-connection-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!