简体   繁体   English

如何使用相同的本地主机,根目录和密码设置多个数据库

[英]how to set multiple databases with same localhost, root and password

application/config/ database.php, How can I set another database with same localhost, Please help! application / config / database.php,如何设置具有相同本地主机的另一个数据库,请帮助! thanks in Advance 提前致谢

$active_group = 'default';
$active_record = TRUE;
$db['default'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'username' => 'root',
 'password' => '',
 'database' => 'business_permit',
 '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
);

The best way is to use different database groups. 最好的方法是使用不同的数据库组。 If you want to keep using the master database as usual ( $this->db ) just turn off persistent connection configuration option to your secondary database(s). 如果要继续照常使用master数据库( $this->db ),只需关闭辅助数据库的持久连接配置选项。 Only master database should work with persistent connection : 只有master数据库应该与持久连接一起工作:

Master database 主数据库

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

Secondary database (notice pconnect is set to false) 辅助数据库(注意pconnect设置为false)

$db['otherdb']['hostname'] = "localhost";
$db['otherdb']['username'] = "root";
$db['otherdb']['password'] = "";
$db['otherdb']['database'] = "other_database_name";
$db['otherdb']['dbdriver'] = "mysql";
$db['otherdb']['dbprefix'] = "";
$db['otherdb']['pconnect'] = FALSE;
$db['otherdb']['db_debug'] = FALSE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = "";
$db['otherdb']['char_set'] = "utf8";
$db['otherdb']['dbcollat'] = "utf8_general_ci";
$db['otherdb']['swap_pre'] = "";
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;

Then you can use secondary databases as database objects while using master database as usual : 然后,您可以照常使用主数据库,而将辅助数据库用作数据库对象:

// use master dataabse
$users = $this->db->get('users');

// connect to secondary database
$otherdb = $this->load->database('otherdb', TRUE);
$stuff = $otherdb->get('struff');
$otherdb->insert_batch('users', $users->result_array());

// keep using master database as usual, for example insert stuff from other database
$this->db->insert_batch('stuff', $stuff->result_array());

Hopes answered your question. 希望回答了您的问题。 Google first before you ask the question... ;) 在您提出问题之前先使用Google ...;)

Codeigniter - multiple database connections Codeigniter-多个数据库连接

you have use environment to use multiple database 您已经使用环境来使用多个数据库

  • create config folder inside production and development folder and add database.php file 在生产和开发文件夹中创建config文件夹,并添加database.php文件
  • then root path index.php file set environment 然后在root路径下设置index.php文件环境

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHPMyAdmin - 为多个数据库设置全局用户和密码 - PHPMyAdmin - set global user and password for multiple databases 设置MySQL根密码时无法连接到“本地主机”上的服务器 - Cannot Connect to Server at 'localhost' when Set the MySQL Root Password 如何使用相同的模型在laravel中管理多个数据库? - How to manage multiple databases in laravel with the same models? SQLSTATE[HY000] [1045] 用户 'root'@'localhost' 的访问被拒绝(使用密码:NO)。 DB_HOST 设置为本地主机 - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) . DB_HOST set to localhost 具有相同结构的多个数据库 - multiple databases with same structure 用户'root'@'localhost'的访问被拒绝(使用密码:NO) - Access denied for user 'root'@'localhost' (using password: NO) 用户'root'@'localhost'访问被拒绝(使用密码:NO); - Access denied for user 'root'@'localhost' (using password: NO); 在 Localhost 上使用 XAMPP 重置 MySQL 根密码 - Resetting MySQL Root Password with XAMPP on Localhost 拒绝“ root @ localhost”访问(使用密码:NO) - Access denied for 'root@localhost' (using password: NO) 无法连接到 MySQL:用户 'root'@'localhost' 的访问被拒绝(使用密码:NO) 我无法访问我的数据库。 我应该做什么 - Could not connect to MySQL: Access denied for user 'root'@'localhost' (using password: NO) I cannot access my databases. What I am supposed to do
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM