search
HomeCMS TutorialPHPCMSHow to connect to the database in phpcms

How to connect to the database in phpcms

How does phpcms connect to the database?

PHPCMS database configuration

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 (
   &#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
   ),
 );
 ?>

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(&#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();
   }
  }

PHP Chinese website, a large number of free PHPCMS tutorials, welcome to learn online!

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.