国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

配置數(shù)據(jù)庫(Laravel風(fēng)格)

webman/database 數(shù)據(jù)庫及版本支持情況如下:

  • MySQL 5.6+
  • PostgreSQL 9.4+
  • SQLite 3.8.8+
  • SQL Server 2017+

    數(shù)據(jù)庫配置文件位置為 config/database.php

    return [
     // 默認(rèn)數(shù)據(jù)庫
     'default' => 'mysql',
     // 各種數(shù)據(jù)庫配置
     'connections' => [
    
         'mysql' => [
             'driver'      => 'mysql',
             'host'        => '127.0.0.1',
             'port'        => 3306,
             'database'    => 'webman',
             'username'    => 'webman',
             'password'    => '',
             'unix_socket' => '',
             'charset'     => 'utf8',
             'collation'   => 'utf8_unicode_ci',
             'prefix'      => '',
             'strict'      => true,
             'engine'      => null,
             'pool' => [ // 連接池配置,僅支持swoole/swow驅(qū)動
                'max_connections' => 5, // 最大連接數(shù)
                'min_connections' => 1, // 最小連接數(shù)
                'wait_timeout' => 3,    // 從連接池獲取連接等待的最大時間,超時后會拋出異常
                'idle_timeout' => 60,   // 連接池中連接最大空閑時間,超時后會關(guān)閉回收,直到連接數(shù)為min_connections
                'heartbeat_interval' => 50, // 連接池心跳檢測時間,單位秒,建議小于60秒
            ],
         ],
    
         'sqlite' => [
             'driver'   => 'sqlite',
             'database' => '',
             'prefix'   => '',
             'pool' => [ // 連接池配置,僅支持swoole/swow驅(qū)動
                'max_connections' => 5, // 最大連接數(shù)
                'min_connections' => 1, // 最小連接數(shù)
                'wait_timeout' => 3,    // 從連接池獲取連接等待的最大時間,超時后會拋出異常
                'idle_timeout' => 60,   // 連接池中連接最大空閑時間,超時后會關(guān)閉回收,直到連接數(shù)為min_connections
                'heartbeat_interval' => 50, // 連接池心跳檢測時間,單位秒,建議小于60秒
            ],
         ],
    
         'pgsql' => [
             'driver'   => 'pgsql',
             'host'     => '127.0.0.1',
             'port'     => 5432,
             'database' => 'webman',
             'username' => 'webman',
             'password' => '',
             'charset'  => 'utf8',
             'prefix'   => '',
             'schema'   => 'public',
             'sslmode'  => 'prefer',
             'pool' => [ // 連接池配置,僅支持swoole/swow驅(qū)動
                'max_connections' => 5, // 最大連接數(shù)
                'min_connections' => 1, // 最小連接數(shù)
                'wait_timeout' => 3,    // 從連接池獲取連接等待的最大時間,超時后會拋出異常
                'idle_timeout' => 60,   // 連接池中連接最大空閑時間,超時后會關(guān)閉回收,直到連接數(shù)為min_connections
                'heartbeat_interval' => 50, // 連接池心跳檢測時間,單位秒,建議小于60秒
            ],
         ],
    
         'sqlsrv' => [
             'driver'   => 'sqlsrv',
             'host'     => 'localhost',
             'port'     => 1433,
             'database' => 'webman',
             'username' => 'webman',
             'password' => '',
             'charset'  => 'utf8',
             'prefix'   => '',
             'pool' => [ // 連接池配置,僅支持swoole/swow驅(qū)動
                'max_connections' => 5, // 最大連接數(shù)
                'min_connections' => 1, // 最小連接數(shù)
                'wait_timeout' => 3,    // 從連接池獲取連接等待的最大時間,超時后會拋出異常
                'idle_timeout' => 60,   // 連接池中連接最大空閑時間,超時后會關(guān)閉回收,直到連接數(shù)為min_connections
                'heartbeat_interval' => 50, // 連接池心跳檢測時間,單位秒,建議小于60秒
            ],
         ],
     ],
    ];

    使用多個數(shù)據(jù)庫

    通過Db::connection('配置名')來選擇使用哪個數(shù)據(jù)庫,其中配置名為配置文件config/database.php中的對應(yīng)配置的key。

    例如如下數(shù)據(jù)庫配置:

 return [
     // 默認(rèn)數(shù)據(jù)庫
     'default' => 'mysql',
     // 各種數(shù)據(jù)庫配置
     'connections' => [

         'mysql' => [
             'driver'      => 'mysql',
             'host'        =>   '127.0.0.1',
             'port'        => 3306,
             'database'    => 'webman',
             'username'    => 'webman',
             'password'    => '',
             'unix_socket' =>  '',
             'charset'     => 'utf8',
             'collation'   => 'utf8_unicode_ci',
             'prefix'      => '',
             'strict'      => true,
             'engine'      => null,
         ],

         'mysql2' => [
              'driver'      => 'mysql',
              'host'        => '127.0.0.1',
              'port'        => 3306,
              'database'    => 'webman2',
              'username'    => 'webman2',
              'password'    => '',
              'unix_socket' => '',
              'charset'     => 'utf8',
              'collation'   => 'utf8_unicode_ci',
              'prefix'      => '',
              'strict'      => true,
              'engine'      => null,
         ],
         'pgsql' => [
              'driver'   => 'pgsql',
              'host'     => '127.0.0.1',
              'port'     =>  5432,
              'database' => 'webman',
              'username' =>  'webman',
              'password' => '',
              'charset'  => 'utf8',
              'prefix'   => '',
              'schema'   => 'public',
              'sslmode'  => 'prefer',
          ],
 ];

像這樣切換數(shù)據(jù)庫。

// 使用默認(rèn)數(shù)據(jù)庫,等價于Db::connection('mysql')->table('users')->where('name', 'John')->first();
$users = Db::table('users')->where('name', 'John')->first();; 
// 使用mysql2
$users = Db::connection('mysql2')->table('users')->where('name', 'John')->first();
// 使用pgsql
$users = Db::connection('pgsql')->table('users')->where('name', 'John')->first();
編輯于2025-04-18 17:20:05 完善本頁 +發(fā)起討論
贊助商