gluephp/glue-database

在 Glue 中使用 mrjgreen/database

0.1.0 2016-05-06 19:37 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:50:02 UTC


README

使用 mrjgreen/databasegluephp/glue

安装

使用 Composer

$ composer require gluephp/glue-database

配置

$app = new Glue\App;

$app->config->override([
    'database' => [
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'username'  => 'root',
        'password'  => 'password',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
    ]
]);

更多配置选项可在 https://github.com/mrjgreen/database 找到

注册

$app->register(
    new Glue\Database\ServiceProvider()
);

获取数据库连接实例

一旦服务提供程序注册,您可以使用以下方式获取 Whoops 实例:

$db = $app->make('Database\Connection');

或使用别名

$db = $app->db;