Question : How to get query cretaed by the prepare statement in PDO

Hi all,

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:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
<?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.

Thanks
Addy

Answer : How to get query cretaed by the prepare statement in PDO

There is no way to get the SQL query, you need to create another class that extends the PDO, where you need to define your code which does this task.

Here one URL to create a custom class for the PDO debugging:

http://daveyshafik.com/archives/605-debugging-pdo-prepared-statements.html

If you need a simple output then try var_dump for the $db which print the entire statistics.

Else in the mysql.log file settings in the my.ini, is also another alternative.

hope this helps
Random Solutions  
 
programming4us programming4us