php Codeigniter 错误“无法使用提供的设置连接到您的数据库服务器”

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

Codeigniter Error "Unable to connect to your database server using the provided settings"

phpcodeigniter

提问by Noumi

When I trying upload this project on my domain m facing error "Unable to connect to your database server using the provided settings"

当我尝试在我的域中上传这个项目时,遇到错误“无法使用提供的设置连接到您的数据库服务器”

I have checked my config.phpand database.phpfile and all the information are correct:

我检查了我的config.phpdatabase.php文件,所有信息都正确:

 $db['default']['hostname'] = "etc.com";
 $db['default']['username'] = "etc"; 
 $db['default']['password'] = "etc@etc";
 $db['default']['database'] = "visiting_link";
 $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"; 

Is any solution to that problem? please refer any helping material. I am using fileZilla.
Thanks !

有什么办法可以解决这个问题吗?请参考任何帮助材料。我正在使用 fileZilla。
谢谢 !

回答by Endel

Setting "db_debug" to false solved my problem.

将“db_debug”设置为 false 解决了我的问题。

I'm using Snow Leopard.

我正在使用雪豹。

EDIT: db_debug just obfuscated my direction. The solution in my case was just the mysql.sock reference path, as solved on this question: Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

编辑:db_debug 只是混淆了我的方向。在我的情况下,解决方案只是 mysql.sock 参考路径,如在此问题上解决的:警告:mysql_connect():[2002] 没有这样的文件或目录(尝试通过 unix:///tmp/mysql.sock 连接)在

OS X use /tmp/mysql.sock, and by default php.ini is referencing /var/mysql/mysql.sock. Just creating a symlink solves the problem:

OS X 使用 /tmp/mysql.sock,默认情况下 php.ini 引用 /var/mysql/mysql.sock。只需创建一个符号链接即可解决问题:

sudo mkdir -p /var/mysql/ && cd /var/mysql/
sudo ln -s /tmp/mysql.sock ./mysql.sock

回答by Dan Murfitt

Try setting the 'dbdriver' to 'mysqli'

尝试将“dbdriver”设置为“mysqli”

$db['default']['dbdriver'] = "mysqli";

It's the MySQL Improved Extension (http://php.net/manual/en/book.mysqli.php) and your server may be set to use this rather than the standard MySQL extension.

它是 MySQL 改进的扩展 ( http://php.net/manual/en/book.mysqli.php) 并且您的服务器可能设置为使用它而不是标准的 MySQL 扩展。

I've seen this happen a few times when all other settings are correct, as the connection will fail if the wrong driver is selected.

当所有其他设置都正确时,我已经看到这种情况发生了几次,因为如果选择了错误的驱动程序,连接将失败。

回答by J. Bruni

If the database settings are correct, than something is wrong anywhere else:

如果数据库设置正确,那么其他地方就会出错:

  • maybe the database does not accept connections from anywhere; in this case, you need to allow connections from your 'username'@'server IP'

  • maybe PHP or the server itself is not allowing the connection, due to a php.ini setting, a firewall, or something else

  • 也许数据库不接受来自任何地方的连接;在这种情况下,您需要允许来自您的“用户名”@“服务器 IP”的连接

  • 由于 php.ini 设置、防火墙或其他原因,PHP 或服务器本身可能不允许连接

Back to the CI DB settings, you need to be sure they are correct. Are you sure the "hostname" is correct?

回到 CI DB 设置,您需要确保它们是正确的。您确定“主机名”正确吗?

回答by Riead Hossion

if u use codeigniter 3 then please use latest version of php. Once i got these errors but then i update my php then it works after successfully setup codeigniter on my project.

如果您使用 codeigniter 3,请使用最新版本的 php。一旦我收到这些错误,然后我更新了我的 php,那么它在我的项目上成功设置 codeigniter 后就可以工作了。

And please follow in your application/config/database.php

并请遵循您的 application/config/database.php

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'db_bdtimes', // your database name
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

回答by Code Spy

I was getting this error

我收到这个错误

    <div id="container">
        <h1>A Database Error Occurred</h1>
        <p>Unable to connect to your database server using the provided settings.</p>
        <p>Filename: C:/xampp/htdocs/WORK/Vishal/UI-Demo/system/database/DB_driver.php</p>
        <p>Line Number: 436</p>
    </div>

I resolved this error by change debug option to FALSE in database.php

我通过在 database.php 中将调试选项更改为 FALSE 解决了这个错误

'db_debug' => (ENVIRONMENT !== 'production'),

'db_debug' =>(环境!== '生产'),

TO

'db_debug' => FALSE,

'db_debug' => 假,

Change this

改变这个

$db['default'] = array(
'dsn'   => '',
'hostname' => 'XXXX',
'username' => 'XXXX',
'password' => 'XXXX',
'database' => 'XXX',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

);

);

To

$db['default'] = array(
'dsn'   => '',
'hostname' => 'XXXX',
'username' => 'XXXX',
'password' => 'XXXX',
'database' => 'XXX',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

);

);

回答by Ananth

This solved my problem while deploying a codeigniter CMS on server, although it was working fine in localhost with TRUE attribute. change this line in database.php to look like this :

这解决了我在服务器上部署 codeigniter CMS 时的问题,尽管它在具有 TRUE 属性的 localhost 中工作正常。将 database.php 中的这一行更改为如下所示:

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

Also CHECK if this line matches the collation of your server's database(for all tables as well):

还要检查此行是否与服务器数据库的排序规则匹配(也适用于所有表):

$db['default']['dbcollat'] = "utf8_general_ci";

回答by Hieu Van Mach

Try this $db['default']['hostname'] = "localhost";

试试这个 $db['default']['hostname'] = "localhost";

回答by Raju George

If you are facing this issue in shared hosting environment. Then i think you have to give the database credentials same as cpanel/hosting credentials.

如果您在共享主机环境中遇到此问题。然后我认为您必须提供与 cpanel/hosting 凭据相同的数据库凭据。

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "cpanel/hosting username"; 
$db['default']['password'] = "cpanel/hosting password";
$db['default']['database'] = "dbname";