Home > Backend Development > PHP Tutorial > How to configure multi-database access in CI, ci database access_PHP tutorial

How to configure multi-database access in CI, ci database access_PHP tutorial

WBOY
Release: 2016-07-12 08:55:06
Original
953 people have browsed it

CI configuration method for multi-database access, ci database access

The example in this article describes the CI configuration method for multi-database access. Share it with everyone for your reference, the details are as follows:

1. Modify the datebase.php file and change:

$db['XXX']['pconnect'] = TRUE;

Copy after login

was changed to:

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

Copy after login

2. Copy the original database link definition, such as the current one

$db['bbs']['hostname'] = '你的数据库IP地址';
$db['bbs']['username'] = '链接用户名';
$db['bbs']['password'] = '数据库连接密码';
$db['bbs']['database'] = '数据库名';
$db['bbs']['dbdriver'] = 'mysql';
$db['bbs']['dbprefix'] = 'cg_';
$db['bbs']['pconnect'] = FALSE;
$db['bbs']['db_debug'] = TRUE;
$db['bbs']['cache_on'] = FALSE;
$db['bbs']['cachedir'] = '';
$db['bbs']['char_set'] = 'utf8';
$db['bbs']['dbcollat'] = 'utf8_general_ci';
$db['bbs']['swap_pre'] = '';
$db['bbs']['autoinit'] = TRUE;
$db['bbs']['stricton'] = FALSE;

Copy after login

No other modifications are required, and then load the constructor in your controller:

function __construct()
{
  parent::__construct();
  $this->XXX= $this->load->database('XXX', TRUE);
  //注意,这里的XXX代表上面的bbs,修改成bbs就行了
}
Copy after login

How to use:

$query = $this->bbs->query($sql);
//和以前一样,就是这里用到了$this->XXX-> XXX就是你定义的bbs
$rs = $query->result();

Copy after login

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

Articles you may be interested in:

  • Complete implementation method of database retrieval example for CI framework
  • Solution to the problem of password user error caused by CI using Tank Auth to transfer the database
  • Code for CI operating multiple databases in php
  • CodeIgniter’s connection, configuration and usage methods for databases
  • Design flaws and solutions for database transaction processing of CodeIgniter framework
  • Database configuration using codeigniter under Sina SAE cloud platform
  • Summary of optimized writing methods for Codeigniter operation database tables
  • Summary of codeigniter database operation functions
  • Let CodeIgniter database cache automatically expire Processing methods
  • Instructions for using the database class provided by codeigniter

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117094.htmlTechArticleCI configuration method for multi-database access, ci database access This article describes the CI configuration method for multi-database access. Share it with everyone for your reference, the details are as follows: 1. Modify dateba...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template