开发者

How to get query created by the prepare statement in PDO

开发者 https://www.devze.com 2023-01-07 16:19 出处:网络
We can use prepare method to get the query prepared for multiple time use in PDO. But i want to know that can we see all the queries executed at the DB.

We can use prepare method to get the query prepared for multiple time use in PDO.

But i want to know that can we see all the queries executed at the DB. For e.g see below:

<?php

    // Cosidering DB connection already set here. With $db.
    // using named placeholder

    $db->prepare("select * from user where id=:id");
    $db->bindParam(':id',$id);

    for($i=1;$i<=5;$i++)
    {
       $id=$i;
       $db->execute();
   开发者_运维技巧 }

?>

OK now we can see that this code will run 5 queries.

So how can i get these queries which is executed by this execute() statement???

Hope I am clear to all.


Afaik, unless you extend the PDO class, I don't think its possible. You possibly can enable a log on your (development) database however. Don't use it in production.

0

精彩评论

暂无评论...
验证码 换一张
取 消