试图让远程数据库服务器在本地使用mysqli [英] Trying to get remote database server working with mysqli locally

查看:188
本文介绍了试图让远程数据库服务器在本地使用mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过Godaddy创建了一个新的数据库,我想通过mysqli连接我的PHP。它无法连接到数据库。由于数据库刚刚创建,也许它仍然没有在后端激活。



我的下一步是尝试从同一主机连接到另一个数据库,我知道一个数据库工作;我目前使用它为一个Wordpress网站,所以我知道它的工作。通过复制数据库信息(主机,用户名,密码,数据库名),我仍然得到相同的错误。



当我在本地数据库上运行它时,Mysqli正在为我工​​作。这是我收到的错误消息(同一消息为两个删除数据库) - 我删除了实际的主机路径,但我保证我从我的wp-config.php复制/粘贴,这是目前正在运行: / p>

这是我得到的错误:

 警告:mysqli :: mysqli()[< a href ='mysqli.mysqli'> mysqli.mysqli< / a>]:
[2002]连接尝试失败,因为连接的方没有
没有正确响应一段时间后,或者建立connecti
(尝试通过tcp://database.db.host.hostedresource.com:3306连接)

如果它是任何用途,以下是我通过PHP连接的方式:

  $ mysqli = new mysqli('database.db.host.hostedresource.com',
'database_user','password','database_name');
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}

任何想法?我知道不可能是事情仍然是建立在Godaddy的结束,因为我现在正试图连接到已经运行了几个月,并且目前正在使用的数据库。



编辑:



我放慢开始实现也许这是一个获得正确权限的问题哪个结束?我不知道)允许我的WAMP连接到远程数据库(godaddy)。

解决方案

在godaddy.com的网站托管界面中,点击 MySQL 下的数据库。它应该使用新数据库打开一个名为管理数据库的对话框。在状态列下,它应该说设置。如果没有,那么您的数据库尚未设置或未正确设置。如果是这种情况,请联系他们的技术支持。否则,请点击数据库名称右侧的操作按钮,然后选择详细信息。确保数据库名称和主机名是您在代码中使用(可能匹配WP使用,但检查首先明显)。也尝试PhpMyAdmin链接,看看是否可以直接访问数据库。我建议只要设置一个不同的数据库,除非你试图做一些与WP数据。



编辑:
看起来你必须在godaddy.com上设置启用了直接数据库访问的数据库: http://support.godaddy.com/help/article/4978/connecting-remotely-to-shared-hosting-databases 。您可能需要不同的托管帐户。


I have created myself a new database through Godaddy, and I'm tyring to connect my PHP to it thru mysqli. It can't connect to the database. Since the database has just been created, maybe it's still not activated in their backend.

My next step was to try to connect to another database from the same hosting, one database that I know works; I'm currently using it for a Wordpress website, so I know it's working. By copying the database info (host, username, password, database name), I still get the same error.

Mysqli is working for me when I run it locally on a local database. Here is the error message I'm getting (same message for both remove databases) - I've removed the actual host path, but I assure I copied/pasted this from my wp-config.php, which is currently running live:

Here is the error I'm getting:

Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: 
[2002] A connection attempt failed because the connected party did 
not properly respond after a period of time, or established connecti 
(trying to connect via tcp://database.db.host.hostedresource.com:3306)

If it's any use, here's how I connect via PHP:

$mysqli = new mysqli('database.db.host.hostedresource.com', 
'database_user', 'password', 'database_name');
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

Any ideas? I know it can't be the fact that stuff are still being set up on godaddy's end, because I am now trying to connect to a database that has been running for months, and is currently being used.

EDIT:

I'm slowing starting to realize maybe it's a question of getting the right permission (on which end? I don't know) to allow my WAMP to connect to a remote database (godaddy). Are there permissions you need to allow for this?

解决方案

In godaddy.com's hosting interface for your website, click on MySQL under Databases. It should open a dialog called Manage Databases with your new database. Under the Status column, it should say "setup". If it doesn't then your database is not setup yet or is not setup correctly. If this is the case, contact their tech support. Otherwise, click on the Actions button to the right of your database name and select Details. Make sure the database name and hostname are what you are using in your code (probably matches what WP uses, but check obvious first). Also try the PhpMyAdmin link and see if you can access the database directly. I would recommend just setting up a different database unless you're trying to do something with the WP data.

Edit: It looks like you have to setup the database on godaddy.com with "direct database access" enabled: http://support.godaddy.com/help/article/4978/connecting-remotely-to-shared-hosting-databases. You may need a different hosting account for that.

这篇关于试图让远程数据库服务器在本地使用mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆