CakeFest 2024: The Official CakePHP Conference

mysqli::debug

mysqli_debug

(PHP 5, PHP 7, PHP 8)

mysqli::debug -- mysqli_debugデバッグ操作を行う

説明

オブジェクト指向型

public mysqli::debug(string $options): true

手続き型

mysqli_debug(string $options): true

Fred Fish debugging library を使用してデバッグを行います。

パラメータ

options

実行するデバッグ操作を表す文字列。

デバッグ操作を表す文字列は、 以下のようなコロン区切りでフィールドを並べたものです:

<field_1>:<field_2>:<field_N>
それぞれのフィールドは、 必須のフラグ文字の後にオプションの , と、カンマ区切りの modifier (修正子) の一覧が続きます: flag[,modifier,modifier,...,modifier]

認識するフラグ文字
options に指定する文字 説明
O MYSQLND_DEBUG_FLUSH
A/a MYSQLND_DEBUG_APPEND
F MYSQLND_DEBUG_DUMP_FILE
i MYSQLND_DEBUG_DUMP_PID
L MYSQLND_DEBUG_DUMP_LINE
m MYSQLND_DEBUG_TRACE_MEMORY_CALLS
n MYSQLND_DEBUG_DUMP_LEVEL
o 出力先のファイル
T MYSQLND_DEBUG_DUMP_TIME
t MYSQLND_DEBUG_DUMP_TRACE
x MYSQLND_DEBUG_PROFILE_CALLS

戻り値

常に true を返します。

変更履歴

バージョン 説明
8.0.0 この関数は、常に true を返すようになりました。 これより前のバージョンでは、失敗時に false を返していました。

例1 トレースファイルの作成

<?php

/* ローカル(クライアント)マシンの '/tmp/client.trace' に
トレースファイルを作成します */
mysqli_debug("d:t:o,/tmp/client.trace");

?>

注意

注意:

mysqli_debug() 関数を使用するには、 MySQL クライアントライブラリを、デバッグ機能を有効にしてコンパイルする 必要があります。

参考

add a note

User Contributed Notes 3 notes

up
28
Peter
9 years ago
can there be more documenation with a small (but working) example script on how to use this ?

Some issues (Ive seen the "same" code example in dozens of tutorials):-

( I'll use capitals for emphasis only)

QUESTION: what does D:T:O mean ? UNEXPLAINED.

QUESTION: Do we *ONLY* use these 3 lines in a self-contained script ? Does this log ALL future MYSQL commands ?

QUESTION :- Do we put that one line just

- immediately after we connect to MYSQL ?
- before we connect to MYSQL ?
- before our suspected error ?
up
6
riversnowchang at gmail dot com
6 years ago
Here are the information about debug options on mysqli_debug()

O,o:MYSQLND_DEBUG_FLUSH
A,a:MYSQLND_DEBUG_APPEND
F:MYSQLND_DEBUG_DUMP_FILE
L:MYSQLND_DEBUG_DUMP_LINE
m:MYSQLND_DEBUG_TRACE_MEMORY_CALLS
n:MYSQLND_DEBUG_DUMP_LEVEL
o:output to file
T:MYSQLND_DEBUG_DUMP_TIME
t:MYSQLND_DEBUG_DUMP_TRACE
x:MYSQLND_DEBUG_PROFILE_CALLS
f:? still investigating

For example, mysqli_debug("T:n:t:m:x:F:L:o,/tmp/client.trace");
mysqlnd will write Time, Level, trace, memory calls, profile calls, File, Line to client.trace file.

22:35:42.704501 ../mysqlnd_connection.c: 269 0:>mysqlnd_connection_init
22:35:42.704538 ../mysqlnd_driver.c: 10 1:| >mysqlnd_driver::get_connection
22:35:42.704549 ../mysqlnd_driver.c: 10 2:| | info : persistent=1
22:35:42.704558 ../mysqlnd_alloc.c: 21 2:| | >_mysqlnd_pecalloc
22:35:42.704570 ../mysqlnd_alloc.c: 23 2:| | <_mysqlnd_pecalloc (total=3 own=3 in_calls=0)
22:35:42.704602 ../mysqlnd_alloc.c: 21 2:| | >_mysqlnd_pecalloc
22:35:42.704626 ../mysqlnd_alloc.c: 23 2:| | <_mysqlnd_pecalloc (total=2 own=2 in_calls=0)
22:35:42.704650 ../mysqlnd_connection.c: 15 2:| | >mysqlnd_error_info_init
22:35:42.704675 ../mysqlnd_connection.c: 10 3:| | | >mysqlnd_error_info::reset
22:35:42.704697 ../mysqlnd_connection.c: 10 3:| | | <mysqlnd_error_info::reset (total=1 own=1 in_calls=0)
22:35:42.704725 ../mysqlnd_connection.c: 16 2:| | <mysqlnd_error_info_init (total=51 own=50 in_calls=1)
22:35:42.704744 ../mysqlnd_connection.c: 21 2:| | >mysqlnd_connection_state_init

If there is anything wrong, please let me know.
up
-1
Domenic
5 years ago
Looks like this manual could be referred to:

http://tiebing.blogspot.com.au/2011/10/cc-dbug-library.html

(I haven't tested it)
To Top