getDBO ($options = []) : object

参数

@param    string|array     $options   字符串代表数据源; 数组代表具体的配置内容

说明

获取一个数据库单例

举栗

假定数据库配置为:

<?php
return array(
    'dbo' => array(
        'test' => array(
            'database_type' => 'mysql',
            'database_name' => 'test',
            'server'        => '127.0.0.1',
            'username'      => 'root',
            'password'      => 'root',
            'charset'       => 'utf8'
        ),
    ),
);

支持使用数据源来调用:

$downloader->onAfterDownloader = function($downloader){
    //dbo single instance
    $downloader->getDbo('test')->select('user', '*');
};

支持使用配置数组调用:

$downloader->onAfterDownloader = function($downloader){
    //dbo single instance
    $config = Configurator::get('globalConfig/database/dbo/test')
    $downloader->getDbo($config)->select('user', '*');
};

results matching ""

    No results matching ""