victor victor - 4 months ago 24
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?


$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!


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 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:


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.