Killing a MySQL query during execution with PHP and AJAX

后端 未结 4 985
萌比男神i
萌比男神i 2021-01-20 16:24

I am creating a custom query builder, when user has created his query he can verify the query syntax by clicking a button. When the user click on the button to verify, An A

4条回答
  •  北海茫月
    2021-01-20 17:11

    I believe that thread_id reported by CONNECTION_ID() is the same as the thread id used in mysqladmin....

    You'd need to capture the process id for the connection before starting the query...

    $qry="SELECT CONNECTION_ID() AS c";
    $row=mysql_fetch_assoc(mysql_query($qry));
    $_SESSION['mysql_connection_id']=$row['c'];
    

    then when the user clicks the button do something like....

    exec('mysqladmin -u $user -p$password killproc ' 
              . $_SESSION['mysql_connection_id']);
    

    But this opens up the possibility of users killing other peoples' queries. You could inject a comment key, e.g. the php session id, at the beginning of each query (mysqladmin truncates text of the query) then use mysqladmin processlist to check the ownership and/or retrieve the thread id before killing it.

提交回复
热议问题