Help us understand the problem. What is going on with this article?

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

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

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

http://fuelphp.jp/docs/1.9/classes/database/db.html#/method_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()用のクエリ文字列も持っているようですね!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした