php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44319 Add access to actual query sent to DB
Submitted: 2008-03-03 21:46 UTC Modified: 2017-04-24 19:12 UTC
Votes:3
Avg. Score:3.7 ± 1.9
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: joe at digg dot com Assigned: adambaratz (profile)
Status: Closed Package: PDO related
PHP Version: 5.2.5 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
42 - 40 = ?
Subscribe to this entry?

 
 [2008-03-03 21:46 UTC] joe at digg dot com
Description:
------------
PEAR's DB (and others?) has a property called DB::$last_query that gives access to the *actual* query sent to the database. For the life of me I can't find this functionality in PDO and it's insanely useful for logging, debugging, etc. I doubt it'd be a big deal to add. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-03 22:10 UTC] joe at digg dot com
I just looked through the code. Looks like what I'm asking for is access to stmt->active_query_string which is in PDOStatement::execute()'s code. I'll poke around a bit more. I'd like access to it whether the statement executes successfully or not so it makes sense to expose it via a member variable. 

I can probably come up with a patch, but would want to do it in a way that'd actually get accepted. Thoughts?
 [2011-04-08 21:27 UTC] jani@php.net
-Package: Feature/Change Request +Package: PDO related
 [2017-04-24 19:12 UTC] adambaratz@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: adambaratz
 [2017-04-24 19:12 UTC] adambaratz@php.net
This feature will be released with PHP 7.2 for emulated prepared statements:
https://wiki.php.net/rfc/debugging_pdo_prepared_statement_emulation_v2

It's not possible for true prepared statements since there is no literal SQL executed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC