php mysql 从另一台服务器连接数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5765711/
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:25:27  来源:igfitidea点击:

php mysql Connect Database from another server

phpmysqldatabase

提问by Hassan

Connect Database from another server in mysql and php I use this :

从mysql和php中的另一台服务器连接数据库我使用这个:

<?php
$db = mysql_connect("mysite.com", "theusername", "proud");
mysql_select_db("theotherserverDB",$db);

?>

need to Fix?

需要修复吗?

回答by Sandeep Bansal

<?php

mysql_connect("mysite.com:3306", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";

?>

Just run it and see if it works.

只需运行它,看看它是否有效。

回答by Anish Charles

Before making the connection.. you should reserve the domain or IP address of the server you are about to communicate from....

在建立连接之前.. 您应该保留您将要与之通信的服务器的域或 IP 地址..

If you are using cpanel you can do this by clicking on remote MYSQL under databases.

如果您使用的是 cpanel,您可以通过单击数据库下的远程 MYSQL 来执行此操作。

Good luck...

祝你好运...