
phpcms method to connect to the database:
Database configuration file location: caches/configs/database.php
We open this configuration file and join us database configuration information. The database configuration information is a two-dimensional array structure. The default is default. Multiple database links can be configured according to the default structure (such as: extended_1)
?<?php
return array (
'default' => array (
'hostname' => 'localhost',
'database' => 'phpcms',
'username' => 'admin',
'password' => 'admin',
'tablepre' => 'v9_',
'charset' => 'gbk',
'type' => 'mysql',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
/* 以下默认不存在 */
'extended_1' => array (
'hostname' => '10.10.125.2',
'database' => 'phpcms',
'username' => 'admin',
'password' => 'admin',
'tablepre' => 'v9_',
'charset' => 'gbk',
'type' => 'mysql',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
);
?> Modify the above configuration content according to your database connection information. After the modification is completed, Save the database configuration file.
After configuring the database, you can select the database configuration file, database, etc. through the database model class below!
The database model is located in: phpcms/model/ directory
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_sys_class('model', '', 0);
class test_model extends model {
public function __construct() {
$this->db_config = pc_base::load_config('database');
$this->db_setting = 'default';
$this->table_name = 'test';
parent::__construct();
}
}
?>PHP Chinese website, a large number of free PHPCMS tutorials, welcome to learn online!
The above is the detailed content of How to connect phpcms to database. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools





