*mysqlnd_qc_get_query_trace_log* -- Returns a backtrace for each query inspected
by the query cache

  array mysqlnd_qc_get_query_trace_log()~

Returns a backtrace for each query inspected by the query cache. The
collection of the backtrace is disabled by default. To collect the backtrace
you have to set the PHP configuration directive mysqlnd_qc.collect_query_trace
to 1

The maximum depth of the backtrace is limited to the depth set with the PHP
configuration directive mysqlnd_qc.query_trace_bt_depth.

This function has no parameters.

An array of query backtrace. Every list entry contains the query string, a
backtrace and further detail information.

<?php >
  /* Connect, create and populate test table */
  $mysqli = new mysqli("host", "user", "password", "schema", "port", "socket");
  $mysqli->query("DROP TABLE IF EXISTS test");
  $mysqli->query("CREATE TABLE test(id INT)");
  $mysqli->query("INSERT INTO test(id) VALUES (1), (2)");
  
  $res = $mysqli->query("SELECT id FROM test WHERE id = 1");
  var_dump($res->fetch_assoc());
  $res->free();
  
  $res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 2");
  var_dump($res->fetch_assoc());
  $res->free();
  
  $res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 2");
  var_dump($res->fetch_assoc());
  $res->free();
?>

The above examples will output:

  array(1) {
    ["id"]=>
    string(1) "1"
  }
  array(1) {
    ["id"]=>
    string(1) "2"
  }
  array(1) {
    ["id"]=>
    string(1) "2"
  }
  array(6) {
    [0]=>
    array(8) {
      ["query"]=>
      string(25) "DROP TABLE IF EXISTS test"
      ["origin"]=>
      string(85) "#0 /home/nixnutz/php/phpdoc/foo.php(7): mysqli->query('DROP TABLE IF E...')
  #1 {main}"
      ["run_time"]=>
      int(0)
      ["store_time"]=>
      int(0)
      ["eligible_for_caching"]=>
      bool(false)
      ["no_table"]=>
      bool(false)
      ["was_added"]=>
      bool(false)
      ["was_already_in_cache"]=>
      bool(false)
    }
    [1]=>
    array(8) {
      ["query"]=>
      string(25) "CREATE TABLE test(id INT)"
      ["origin"]=>
      string(85) "#0 /home/nixnutz/php/phpdoc/foo.php(8): mysqli->query('CREATE TABLE te...')
  #1 {main}"
      ["run_time"]=>
      int(0)
      ["store_time"]=>
      int(0)
      ["eligible_for_caching"]=>
      bool(false)
      ["no_table"]=>
      bool(false)
      ["was_added"]=>
      bool(false)
      ["was_already_in_cache"]=>
      bool(false)
    }
    [2]=>
    array(8) {
      ["query"]=>
      string(36) "INSERT INTO test(id) VALUES (1), (2)"
      ["origin"]=>
      string(85) "#0 /home/nixnutz/php/phpdoc/foo.php(9): mysqli->query('INSERT INTO tes...')
  #1 {main}"
      ["run_time"]=>
      int(0)
      ["store_time"]=>
      int(0)
      ["eligible_for_caching"]=>
      bool(false)
      ["no_table"]=>
      bool(false)
      ["was_added"]=>
      bool(false)
      ["was_already_in_cache"]=>
      bool(false)
    }
    [3]=>
    array(8) {
      ["query"]=>
      string(32) "SELECT id FROM test WHERE id = 1"
      ["origin"]=>
      string(86) "#0 /home/nixnutz/php/phpdoc/foo.php(11): mysqli->query('SELECT id FROM ...')
  #1 {main}"
      ["run_time"]=>
      int(0)
      ["store_time"]=>
      int(15)
      ["eligible_for_caching"]=>
      bool(false)
      ["no_table"]=>
      bool(false)
      ["was_added"]=>
      bool(false)
      ["was_already_in_cache"]=>
      bool(false)
    }
    [4]=>
    array(8) {
      ["query"]=>
      string(41) "/*qc=on*/SELECT id FROM test WHERE id = 2"
      ["origin"]=>
      string(86) "#0 /home/nixnutz/php/phpdoc/foo.php(15): mysqli->query('/*qc=on*/SELECT...')
  #1 {main}"
      ["run_time"]=>
      int(340)
      ["store_time"]=>
      int(3)
      ["eligible_for_caching"]=>
      bool(true)
      ["no_table"]=>
      bool(false)
      ["was_added"]=>
      bool(true)
      ["was_already_in_cache"]=>
      bool(false)
    }
    [5]=>
    array(8) {
      ["query"]=>
      string(41) "/*qc=on*/SELECT id FROM test WHERE id = 2"
      ["origin"]=>
      string(86) "#0 /home/nixnutz/php/phpdoc/foo.php(19): mysqli->query('/*qc=on*/SELECT...')
  #1 {main}"
      ["run_time"]=>
      int(4)
      ["store_time"]=>
      int(2)
      ["eligible_for_caching"]=>
      bool(true)
      ["no_table"]=>
      bool(false)
      ["was_added"]=>
      bool(false)
      ["was_already_in_cache"]=>
      bool(true)
    }
  }

Runtime configuration mysqlnd_qc.collect_query_trace
mysqlnd_qc.query_trace_bt_depth mysqlnd_qc.time_statistics
mysqlnd_qc.cache_no_table

vim:ft=help:
