CI配置多数据库访问的方法,ci数据库访问
CI配置多数据库访问的方法,ci数据库访问
本文实例讲述了CI配置多数据库访问的方法。分享给大家供大家参考,具体如下:
1、修改datebase.php文件,将:
$db['XXX']['pconnect'] = TRUE;
修改成:
$db['XXX']['pconnect'] = FALSE;
2、将原来的数据库链接定义复制一份,如当前
$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;
其他的都不需要修改,然后在你的控制器里面加载 构造函数:
function __construct() { parent::__construct(); $this->XXX= $this->load->database('XXX', TRUE); //注意,这里的XXX代表上面的bbs,修改成bbs就行了 }
使用方式:
$query = $this->bbs->query($sql); //和以前一样,就是这里用到了$this->XXX-> XXX就是你定义的bbs $rs = $query->result();
更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
- CI框架入门示例之数据库取数据完整实现方法
- CI使用Tank Auth转移数据库导致密码用户错误的解决办法
- php中CI操作多个数据库的代码
- CodeIgniter针对数据库的连接、配置及使用方法
- CodeIgniter框架数据库事务处理的设计缺陷和解决方案
- 新浪SAE云平台下使用codeigniter的数据库配置
- Codeigniter操作数据库表的优化写法总结
- codeigniter数据库操作函数汇总
- 让CodeIgniter数据库缓存自动过期的处理的方法
- codeigniter自带数据库类使用方法说明

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.
