A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: libraries/Session/Session.php
Line Number: 102
我是 CI 新手,当我启动 Db 到我的网站时,我收到此错误,但我不知道如何解决。
您能解决这个错误吗?
应用程序/config/database.php
$active_group = 'default';
$query_builder = TRUE;
require_once('mainconfig.php');
$db['default'] = array(
'dsn' => '',
'hostname' => $config['mysql_host'],
'username' => $config['mysql_username'],
'password' => $config['mysql_password'],
'database' => $config['mysql_database'],
'dbdriver' => $config['mysql_driver'],
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => $config['mysql_charset'],
'dbcollat' => $config['mysql_dbcollat'],
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
应用程序/config/mainconfig.php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['mysql_host'] = 'localhost';
$config['mysql_username'] = 'xxxcc';
$config['mysql_password'] = 'xxxcc';
$config['mysql_database'] = 'xxccv';
$config['mysql_driver'] = 'mysqli';
$config['mysql_charset'] = 'utf8';
$config['mysql_dbcollat'] = 'utf8_general_ci';
$config['base_js'] = 'assets/js';
$config['base_css'] = 'assets/css';
$config['base_plugins'] = 'assets/plugins';
$config['base_images'] = 'assets/images';
$config['base_fonts'] = 'assets/font-awesome';
$config['other_base'] = 'assets/fonts';
$config['email_author'] = 'admin@localhost';
$config['limit'] = 7;
最佳答案
如果您使用 codeigniter 3,请使用最新版本的 php。一旦我收到这些错误,但随后我更新了我的 php,那么在我的项目上成功设置 codeigniter 后它就可以工作了。
请遵循您的 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
);
关于php - CodeIgniter:无法使用提供的连接到您的数据库服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111646/