商会资讯

 找回密码
 立即注册

QQ登录

只需一步,快速开始

用新浪微博连接

一步搞定

搜索
热搜: 活动 交友 discuz

phpcms v9 数据库分离部署

已有 2691 次阅读2012-11-10 11:15 |个人分类:phpcms|

v9数据模型功能,允许用户把不同的数据表,分离到不同的数据库服务器上。以实现负载的分离,更加的符合大访问网站的需求。 



数据分离方法

1.数据库连接配置
配置文件路径:caches\configs\database.php
  1. return array (     
  2.   'default' => array (         
  3.     'hostname' => 'localhost',         
  4.     'database' => 'phpcmsv9',         
  5.     'username' => 'admin',         
  6.     'password' => 'admin',         
  7.     'tablepre' => 'v9_',         
  8.     'charset' => 'gbk',         
  9.     'type' => 'mysql',         
  10.     'debug' => true,         
  11.     'pconnect' => 0,         
  12.     'autoconnect' => 0         
  13.   ),     
  14. /*可以根据自己需求设置多个数据库链接配置*/   
  15.   'link1' => array (         
  16.     'hostname' => 'localhost',         
  17.     'database' => 'comment',         
  18.     'username' => 'admin',         
  19.     'password' => 'admin',         
  20.     'tablepre' => 'v9_',         
  21.     'charset' => 'gbk',         
  22.     'type' => 'mysql',         
  23.     'debug' => true,         
  24.     'pconnect' => 0,         
  25.     'autoconnect' => 0         
  26.   ),     
  27.   'link2' => array (         
  28.     'hostname' => 'localhost',         
  29.     'database' => 'workflow',         
  30.     'username' => 'admin',         
  31.     'password' => 'admin',         
  32.     'tablepre' => 'v9_',         
  33.     'charset' => 'gbk',         
  34.     'type' => 'mysql',         
  35.     'debug' => true,         
  36.     'pconnect' => 0,         
  37.     'autoconnect' => 0         
  38.   ),           
  39. );

2.数据模型配置

配置文件路径:phpcms\model中所有文件

该目录下所有*_model.class.php都是数据模型文件

例如:workflow_model.class.php

  1. defined('in_phpcms') or exit('no permission resources.');
  2. pc_base::load_sys_class('model', '', 0);
  3. class workflow_model extends model {
  4. public function __construct() {     
  5.     $this->db_config = pc_base::load_config('database');     
  6.     $this->db_setting = 'link2'; //可以通过修改db_setting设置该数据表所链接的数据库服务器     
  7.     $this->table_name = 'workflow';     
  8.     parent::__construct();
  9. }
  10. }
 
收藏 分享邀请 转发到微博 举报

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

回顶部