代码点火器错误:无法使用提供的设置连接到您的数据库服务器。文件名:core/Loader.php 行号:346

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

code igniter error: Unable to connect to your database server using the provided settings. Filename: core/Loader.php Line Number: 346

phpmysqlcodeigniter

提问by stormrage

I'm developing a website application using codeigniter at localhost and then i host it in hawkhost.

我正在本地主机上使用 codeigniter 开发一个网站应用程序,然后我将它托管在 hawkhost 中。

At localhost it runs well, but at host there's and error :

在 localhost 它运行良好,但在主机上有错误:

Unable to connect to your database server using the provided settings. Filename: core/Loader.php Line Number: 346

无法使用提供的设置连接到您的数据库服务器。文件名:core/Loader.php 行号:346

this is my db configuration

这是我的数据库配置

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

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '****';
$db['default']['password'] = '****';
$db['default']['database'] = '****';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;

I know many people already asked this problem but it doesn't seems to solve anything on my case. changing $db['default']['db_debug'] = TRUE;to false only hide the error but when i tried to get data from query it doesn't return anything.

我知道很多人已经问过这个问题,但它似乎无法解决我的任何问题。更改$db['default']['db_debug'] = TRUE;为 false 只会隐藏错误,但是当我尝试从查询中获取数据时,它不会返回任何内容。

I also tried to change $db['default']['pconnect'] = FALSE;to true and still doesn't work.

我也试过改成$db['default']['pconnect'] = FALSE;true,还是不行。

Any help please?

请问有什么帮助吗?

回答by vikram eklare

In my case setting pconnect to false worked.

在我的情况下,将 pconnect 设置为 false 有效。

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

回答by Developer

Just change localhostto the local ipaddress i.e. 127.0.0.1and it will start working.

只需更改localhost为本地 ipaddress ie 127.0.0.1,它就会开始工作。

$db['default']['hostname'] = 'localhost';

to

$db['default']['hostname'] = '127.0.0.1';

回答by stormrage

The problem is really due to credentials. I test it using simple code to check if connection can be made.

问题实际上是由于凭据。我使用简单的代码测试它以检查是否可以建立连接。

The problem is in username, i realize there's additional suffix when using hosting. such as suffix_userI think the same errors in Core/Loader.php Line Number: 346 has the same solution. make sure the username, password and host are right.

问题出在用户名上,我意识到使用托管时还有其他后缀。例如suffix_user我认为 Core/Loader.php Line Number: 346 中的相同错误具有相同的解决方案。确保用户名、密码和主机正确。

It's solved. Thank you everyone for helping.

解决了。谢谢大家的帮助。

回答by Shiplu

Most of the time this problem happens when codeigniter is in live environment.

大多数情况下,当 codeigniter 在实时环境中时会发生此问题。

That's why I assumed a domain name ‘(example: domainname.com)' and after creating a mysql database (example: testDb) and user name (example: testUser) you will find a prefix name automatically added with your mysql database name and user name like ‘domainname_ testDb' and ‘domainname_ testUser'.

这就是为什么我假设一个域名 '(example: domainname.com)' 并且在创建一个 mysql 数据库(例如:testDb)和用户名(例如:testUser)后,你会发现一个前缀名称自动添加了你的 mysql 数据库名称和用户'domainname_ testDb' 和 'domainname_ testUser' 之类的名称。

Now in codeigniter /application/config/database.php edit following:

现在在 codeigniter /application/config/database.php 中编辑以下内容:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'domainname_ testDb ';
$db['default']['password'] = '*******';
$db['default']['database'] = 'domainname_ testUser';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;

回答by Mario Estrada

Just change

只是改变

$db['default']['hostname'] = 'localhost';

to

$db['default']['hostname'] = '127.0.0.1';

and voila.

瞧。

回答by Nguy?n Th? Nguy?t

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'domainname_ testDb ';
$db['default']['password'] = '*******';
$db['default']['database'] = 'domainname_ testUser';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;