コード例 #1
0
ファイル: db.php プロジェクト: rezon/sugi
// $dbd = new \Sugi\Database\Sqlite3($config[$driver]);
// $db = new Database($dbd);
// second method - invoking static factory method
// $db = Database::factory($config);
// third method - using factory method with Module
// Module::set("Database", function() use ($config) {
//  	return Database::factory($config);
// });
// $db = Module::get("Database");
// forth method - Setting config params in Module. Factory will be auto invoked
// This is preferred method if Module::get is invoked in several files
// Module::set("Database", $config);
// $db = Module::get("Database");
// direct Module creation
// $db = Module::get("DB", $config);
$db = DB::configure($config);
$db->hook("post_open", function ($action, $data) use($db) {
    global $driver;
    echo "<p>BD connection is established automatically</p>";
    // MySQL specific routines
    if ($driver == "mysql") {
        $db->query("SET NAMES utf8");
        $db->query("CREATE TABLE IF NOT EXISTS test (id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, val VARCHAR(255))");
        // $res = $db->query("INSERT INTO test(val) VALUES ('PHP is cool!')");
        // $res = $db->query($db->bindParams("INSERT INTO test(val) VALUES (:val)", array("val" => 'Sugi')));
    } elseif ($driver == "sqlite" or $driver == "sqlite3") {
        // since we use MEMORY table we need them to be created on every DB connection
        $db->query("CREATE TABLE test (id integer not null primary key, val varchar(255))");
        $res = $db->query("INSERT INTO test(val) VALUES ('PHP is cool!')");
        $res = $db->query($db->bindParams("INSERT INTO test(val) VALUES (:val)", array("val" => 'Sugi')));
    } elseif ($driver == "pgsql") {
コード例 #2
0
ファイル: common.php プロジェクト: beaver-dev/featherbb
        \DB::configure('sqlite:./' . $db_name);
        break;
    case 'pgsql':
        \DB::configure('pgsql:host=' . $db_host . 'dbname=' . $db_name);
        break;
}
\DB::configure('username', $db_username);
\DB::configure('password', $db_password);
\DB::configure('id_column_overrides', array($db_prefix . 'groups' => 'g_id'));
// Log queries if needed
if (defined('FEATHER_SHOW_QUERIES')) {
    \DB::configure('logging', true);
}
// Cache queries if needed
if (defined('FEATHER_CACHE_QUERIES')) {
    \DB::configure('caching', true);
}
// Load cached config
if (file_exists(FORUM_CACHE_DIR . 'cache_config.php')) {
    include FORUM_CACHE_DIR . 'cache_config.php';
}
if (!defined('FEATHER_CONFIG_LOADED')) {
    if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) {
        require FEATHER_ROOT . 'include/cache.php';
    }
    generate_config_cache();
    require FORUM_CACHE_DIR . 'cache_config.php';
}
// Inject config to SlimFramework
$feather->config = $feather_config;
// Enable output buffering