无法使用CodeIgniter连接到MySQL。可能的DNS问题?

时间:2012-08-22 19:39:01

标签: mysql codeigniter

我正在运行带有Codeigniter的开发灯。但是,当我尝试加载页面时,数据库无法连接(数据库实际上在另一台服务器上),我收到此错误:

A Database Error Occurred

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

Filename: core/Loader.php

Line Number: 346

我的database.php是这样的:

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'myhost.com';
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'mytable';
$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;

如果我将'pconnect'和/或'db_debug'更改为false,我会收到相同的错误,或者它只是不起作用。我知道数据库已启动并正常运行,因为其他人可以连接并使用它。

但是,如果我将主机的IP地址放入database.php文件中,它就可以工作。 我尝试刷新DNS甚至改为谷歌的DNS服务器都无济于事。

简单的mysql_connect的结果是:

A PHP Error was encountered

Severity: Warning

Message: mysql_connect(): php_network_getaddresses: getaddrinfo failed: Name or service    not known

Filename: config/database.php

Line Number: 67

A PHP Error was encountered

Severity: Warning

Message: mysql_connect(): [2002] php_network_getaddresses: getaddrinfo failed: Name or     service not known (trying to connect via tcp://myhost.com:3306)

Filename: config/database.php

Line Number: 67

A PHP Error was encountered

Severity: Warning

Message: mysql_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

Filename: config/database.php

Line Number: 67

Could not connect: php_network_getaddresses: getaddrinfo failed: Name or service not known 

2 个答案:

答案 0 :(得分:2)

尝试更改此

$db['default']['db_debug'] = TRUE;

到此:

$db['default']['db_debug'] = FALSE;

答案 1 :(得分:1)

确保域名已注册到正确的I.P.地址和您的主人拥有此确切地址的记录。尝试在网站上放置一个静态HTML文件,您只需要显示“Hello World”文本,以确保您能够通过域名访问该网站。

确保您已在脚本中正确插入域名,并且您可以通过复制和粘贴使用所需凭据登录到PHPMyAdmin(或您使用的任何内容)(没有前导和尾随空格,请注意这一点)。

如果表名有问题,应该这样说。至于其他设置,我对它们中的任何一个都不熟悉,但我在这里概述的应该看到你的数据库工作。

祝你好运。