通过CodeIgniter连接到远程数据库 [英] Connecting to a remote database through CodeIgniter

查看:358
本文介绍了通过CodeIgniter连接到远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


无法使用提供的设置连接到数据库服务器。

Unable to connect to your database server using the provided settings.

我无法将我的应用程式连结到我的远端资料库。我运行我的应用程序时收到上面显示的错误。我在这个网站上看过这个问题的以前的答案,但我没有运气解决它。从我学到的东西,我需要替换主机名,并使我的mysql数据库接受外部连接,我已经做了。我试图在我的database.php通过mysql命令行相同的值,它的工作原理。

I've been having difficulty connecting my application to my remote database. I'm receiving the error shown above when I run my application. I've looked at previous answers to this question on this site, but I've gotten no luck at solving it. From what I learnt, I need to replace the hostname and make my mysql database accept external connections, which I have both done. I tried the same values in my database.php through the mysql command-line and it works.

还有什么可能会丢失?

这是我在database.php中的设置:

Here are my settings in database.php:

$active_group = 'staging';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'myDatabase';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

$db['staging']['hostname'] = 'XX.XX.XXX.XXX';
$db['staging']['username'] = 'user';
$db['staging']['password'] = 'pwd';
$db['staging']['database'] = 'myDatabase';
$db['staging']['dbdriver'] = 'mysql';
$db['staging']['dbprefix'] = '';
$db['staging']['pconnect'] = TRUE;
$db['staging']['db_debug'] = TRUE;
$db['staging']['cache_on'] = FALSE;
$db['staging']['cachedir'] = '';
$db['staging']['char_set'] = 'utf8';
$db['staging']['dbcollat'] = 'utf8_general_ci';
$db['staging']['swap_pre'] = '';
$db['staging']['autoinit'] = TRUE;
$db['staging']['stricton'] = FALSE;


推荐答案

从shell中试试这个命令,看看是否可以connect:

try this command from your shell to see if you can connect:

mysql -h HOSTNAME -uUSERNAME -p DATABASE

还要检查是否没有其他端口连接到mysql集合,默认情况下codeigniter将连接到3306,除非您定义实际的端口集。这可能是问题。

also check to see if you don't have a different port to connect to mysql set, by default codeigniter will connect to 3306, unless you define the actual port set. this might be the issue.

好运气

这篇关于通过CodeIgniter连接到远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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