0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FuelPHPでDBのコネクションを取得する方法

Posted at

DBのコネクションの確認をしたと思って試してみました。

DBクラスの**instance()**メソッドが使用できます。

instance メソッドは Database_Connection のインスタンスを返します。 例えば同時に複数のデータベース接続を使用する必要がある場合など、 データベースインスタンスに直接アクセスすることができます。

// デフォルトの接続を取得
$db = DB::instance(); // or 'default'

// 名前を指定して接続を取得
$db = DB::instance('backup');
// 出力結果

object(Database_MySQLi_Connection)#26 (10) {
  ["_connection":protected]=>
  object(mysqli)#31 (19) {
    ["affected_rows"]=>
    int(1)
    ["client_info"]=>
    string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: b39695XXX2d1d9ed7902b8bae237XXXXXXXX $"
    ["client_version"]=>
    int(50012)
    ["connect_errno"]=>
    int(0)
    ["connect_error"]=>
    NULL
    ["errno"]=>
    int(0)
    ["error"]=>
    string(0) ""
    ["error_list"]=>
    array(0) {
    }
    ["field_count"]=>
    int(0)
    ["host_info"]=>
    string(25) "Localhost via UNIX socket"
    ["info"]=>
    NULL
    ["insert_id"]=>
    int(4272)
    ["server_info"]=>
    string(6) "5.6"
    ["server_version"]=>
    int(50635)
    ["stat"]=>
    string(136) "Uptime: 8192  Threads: 3  Questions: 1040  Slow queries: 0  Opens: 311  Flush tables: 1  Open tables: 304  Queries per second avg: 0.126"
    ["sqlstate"]=>
    string(5) "00000"
    ["protocol_version"]=>
    int(10)
    ["thread_id"]=>
    int(24)
    ["warning_count"]=>
    int(0)
  }
  ["_connection_id":protected]=>
  string(40) "2c02b1be7ed4e8b313b2df2afXXXXXXXXXXX"
  ["_identifier":protected]=>
  string(1) "`"
  ["_db_type"]=>
  string(5) "mysql"
  ["last_query"]=>
  string(294) "INSERT INTO user mask...XXXXXX"
  :
  :
  {省略}

中を見てみると、このインスタンスに**last_query()**用のクエリ文字列も持っているようですね!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?