0

I understood that it might not be possible to get the finally executed query used by PDO because of the way PDO works but I will appreciate any work around to this. I really need to view the exact query for debugging purpose. Your help will be appreciated.

$sql = "Update country SET name=:name, code=:code, dial_code=dial_code, flag=:flag, capital=:capital, region=:region, region_des:region_des WHERE id=:id";
$stmt = $pdo->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->bindParam(':id',$c->getId(), PDO::PARAM_INT);
$stmt->bindParam(':name',$c->getName(), PDO::PARAM_STR);
$stmt->bindParam(':code',$c->getCode(), PDO::PARAM_STR);
$stmt->bindParam(':dial_code',$c->getDialCode(), PDO::PARAM_STR);
$stmt->bindParam(':flag',$c->getFlag(), PDO::PARAM_STR);
$stmt->bindParam(':capital',$c->getCapital(), PDO::PARAM_STR);
$stmt->bindParam(':region',$c->getRegion(), PDO::PARAM_STR);
$stmt->bindParam(':region_des',$c->getRegionDes(), PDO::PARAM_STR);

$stmt->execute();

//error_log("I need the query here.....")
Paullo
  • 2,038
  • 4
  • 25
  • 50
  • 3
    With prepared statements there is no query to dump,so you have to build it echoing the variables OR use mysql log http://stackoverflow.com/a/2413308/1745672 – Mihai Aug 24 '14 at 11:14
  • 1
    I use this [PDO Debug Library](https://github.com/panique/pdo-debug). It's extremely easy to use and does exactly what you expect, spits out the constructed SQL statement. – Ohgodwhy Aug 24 '14 at 11:17
  • Thanks Ohgodowhy and Mihai I am considering using mysql log according Nathan Long on the question link posted by Mihai. But I will still look the Debug Library anyways. I appreciate guys – Paullo Aug 24 '14 at 11:24

0 Answers0