Skip to content
吟夢ちゃん edited this page Aug 12, 2017 · 6 revisions

Database

The database class uses Medoo.

For more information, please click here

After you have configured several constants for the database in the entry file, you can invoke the database layer in a singleton mode, support single database, or multiple databases.

single database

    'db' => array(
        'THE NAME YOU WANTED' => array(
            'host' => '127.0.0.1',
            'user' => 'root',
            'pwd' => '123456',
            'name' => 'test',
            'type' => 'mysql',
            'port' => 3306,// not necessary
            'charset' => 'utf8'// not necessary
        ),
    )

Use $this->db to get the database instance

multiple databases

    'db' => array(
        'test' => array(
            'host' => '127.0.0.1',
            'user' => 'root',
            'pwd' => '123456',
            'name' => 'test',
            'type' => 'mysql',
        ),
        'dist' => array(
            'host' => '127.0.0.1',
            'user' => 'root',
            'pwd' => '123456',
            'name' => 'dist',
            'type' => 'mysql',
        ),
        'dev' => array(
            'host' => '127.0.0.1',
            'user' => 'root',
            'pwd' => '123456',
            'name' => 'dev',
            'type' => 'mysql',
        ),
    )

Use $this->db($key) to get a database instance, such as $this->db('test'), $this->db ('dist').

Clone this wiki locally