Home > CMS Tutorial > PHPCMS > body text

How to configure the database in phpcms

王林
Release: 2020-02-06 11:42:21
Original
3183 people have browsed it

How to configure the database in phpcms

Database configuration file location: caches/configs/database.php

Open this configuration file and add our 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)

The details are as follows:

 <?php
 return array (
   &#39;default&#39; => array (
     &#39;hostname&#39; => &#39;localhost&#39;,
     &#39;database&#39; => &#39;phpcms&#39;,
     &#39;username&#39; => &#39;admin&#39;,
     &#39;password&#39; => &#39;admin&#39;,
     &#39;tablepre&#39; => &#39;v9_&#39;,
     &#39;charset&#39; => &#39;gbk&#39;,
     &#39;type&#39; => &#39;mysql&#39;,
     &#39;debug&#39; => true,
     &#39;pconnect&#39; => 0,
     &#39;autoconnect&#39; => 0
   ),
    /* 以下默认不存在 */
   &#39;extended_1&#39; => array (
     &#39;hostname&#39; => &#39;10.10.125.2&#39;,
     &#39;database&#39; => &#39;phpcms&#39;,
     &#39;username&#39; => &#39;admin&#39;,
     &#39;password&#39; => &#39;admin&#39;,
     &#39;tablepre&#39; => &#39;v9_&#39;,
     &#39;charset&#39; => &#39;gbk&#39;,
     &#39;type&#39; => &#39;mysql&#39;,
     &#39;debug&#39; => true,
     &#39;pconnect&#39; => 0,
     &#39;autoconnect&#39; => 0
   ),
 );
 ?>
Copy after login

Modify according to your database connection information After modifying the above configuration content, 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(&#39;IN_PHPCMS&#39;) or exit(&#39;No permission resources.&#39;);
   pc_base::load_sys_class(&#39;model&#39;, &#39;&#39;, 0);
   class test_model extends model {
     public function __construct() {
     $this->db_config = pc_base::load_config(&#39;database&#39;);
     $this->db_setting = &#39;default&#39;;
     $this->table_name = &#39;test&#39;;
     parent::__construct();
   }
  }
?>
Copy after login

Recommended related articles and tutorials: phpcms tutorial

The above is the detailed content of How to configure the database in phpcms. For more information, please follow other related articles on the PHP Chinese website!

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