我正在尝试将网站上传到服务器。代码点火器是我用于此站点的框架,我第一次使用CI。尝试将网站上传到具有以下数据库setiings的服务器时:
$db['default'] = array(
'dsn' => 'mysql:host=localhost;dbname=database_name',
'hostname' => 'mysql:host=localhost',
'username' => 'database_user',
'password' => 'database_password',
'database' => 'database_name',
'dbdriver' => 'pdo',
'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
);
我一直在收到如下错误,我试图搜索网络以解决我的问题。我发现了一些类似于我的问题,但我无法弄清楚我应该做什么,因为大多数问题都是针对本地服务器的。请有人帮我解决,谢谢。
A Database Error Occurred
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
Filename: controllers/Home.php
Line Number: 9
A PHP Error was encountered
Severity: Warning
Message: PDO::__construct(): The server requested authentication method unknown to the client [mysql_old_password]
Filename: pdo/pdo_driver.php
Line Number: 133
Backtrace:
修改
答案 0 :(得分:0)
尝试:
$db['default'] = array(
'hostname' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => '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
);
或
$db['default'] = array(
'dsn' => 'mysql:host=localhost;dbname=codeigniter',
'username' => 'codeigniter',
'password' => 'codeigniter',
'database' => 'codeigniter',
'dbdriver' => 'pdo',
'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
);
答案 1 :(得分:0)
您可以在database.php中使用此代码进行数据库设置
$active_group = 'live';
$active_record = TRUE;
$db['live']['hostname'] = 'localhost';
$db['live']['username'] = 'user';
$db['live']['password'] = 'password';
$db['live']['database'] = 'database';
$db['live']['dbdriver'] = 'pdo';
$db['live']['dbprefix'] = '';
$db['live']['pconnect'] = TRUE;
$db['live']['db_debug'] = TRUE;
$db['live']['cache_on'] = FALSE;
$db['live']['cachedir'] = '';
$db['live']['char_set'] = 'utf8';
$db['live']['dbcollat'] = 'utf8_general_ci';
$db['live']['swap_pre'] = '';
$db['live']['autoinit'] = TRUE;
$db['live']['stricton'] = FALSE;
在config.php中设置$config["useDatabaseConfig"] = true;
我希望它对你有用。