?phpclass My_model extends CI_Model{public function __construct(){parent::__construct();$db_conn['hostname'] = localhost;$db_conn['username'] = root;$db_conn['password'] = nagiosxi;$db_conn['database'] = web;$db_conn['dbdriver'] = mysql;$d
<?php
class My_model extends CI_Model
{
public function __construct()
{
parent::__construct();
$db_conn['hostname'] = "localhost";
$db_conn['username'] = "root";
$db_conn['password'] = "nagiosxi";
$db_conn['database'] = "web";
$db_conn['dbdriver'] = "mysql";
$db_conn['dbprefix'] = "";
$db_conn['pconnect'] = FALSE;
$db_conn['db_debug'] = TRUE;
$db_conn['port'] = 3306;
$this->load->database($db_conn);
//从此处提交配置参数,可以自定义数据库连接,可以有多个数据库的连接,不依靠config项里的单一数据库配置。
//另一处自定义配置数据库连接参数的地方是在调用模块的地方
//$this->load->mode('My_model', '别名',$db_conn); //别名可以无
}
}
?>也可以在./config/database.php 里定义数据库连接数组,在调用$this->load->database('组名');
例:
./config/database.php
$config['my']['hostname'] = 'localhost';
$config['my']['username'] = 'root';
Difeye是一款超轻量级PHP框架,主要特点有: Difeye是一款超轻量级PHP框架,主要特点有: ◆数据库连接做自动主从读写分离配置,适合单机和分布式站点部署; ◆支持Smarty模板机制,可灵活配置第三方缓存组件; ◆完全分离页面和动作,仿C#页面加载自动执行Page_Load入口函数; ◆支持mysql,mongodb等第三方数据库模块,支持读写分离,分布式部署; ◆增加后台管理开发示例
0
调用:
$this->load->database('my');
http://codeigniter.org.cn/user_guide/database/connecting.html 这是说明地址
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号