victor victor - 1 month ago 5
MySQL Question

How to get MySQL query process id executed by PHP

Is there a way to get the query process id that just issued by PHP mysqli_query or PDO?

sample..

$result = mysqli_query("SELECT * FROM table");


And I want to get the process id of that specific query. If anyone here has ideas on how to solve this I would really appreciate it.. THank you!

Answer

I'm not sure what you mean with "process id", but if you want to get the thread id of the currect mysql connection, you can do this with:

MySQLi Object orientated style:

/* MySQL thread id */
$thread_id = $mysqli->thread_id;

/* Kill connection */
$mysqli->kill($thread_id);

MySQLi procedural style:

/* MySQL thread id */
$thread_id = mysqli_thread_id($mysqli);

/* Kill connection */
mysqli_kill($mysqli, $thread_id);

Using MySQL to get the thread ID in general:

$query = "SELECT CONNECTION_ID()";

It's not like every query has its own "process". Every connection has. As long as you don't close the connection, the thread id will remain the same for each query.

Comments