PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #5013

Member to retrieve last fully formed query upon error

Details

Request #5013Member to retrieve last fully formed query upon error
Submitted2005-08-05 16:10 UTC
Fromct at piglets dot com
StatusWont fix
PackageDB
PHP VersionIrrelevant
OSNot relevant
Roadmaps(Not assigned)

Comments

[2005-08-05 16:10 UTC] ct at piglets dot com

Description:
------------
If a well formed query is eventually placed to the database layer, it can be examined with the use of

DB_Result::getQuery()

but unfortunately, if the query has some error (perhaps as a result of a NULL variable being sent to a placeholder) and an error object is returned then this is not possible.

When I'm using the regular mysql interface in PHP I usually put in code to catch all sql errors so I can log them, but with this new system it seems I can't get the query as it was finally passed to MySQL.

Could getQuery be added to the error object please? Apologies if I've missed something obvious.

Test script:
---------------
// $mime_id has not been set, due to error, or user input
// not fully validated

$sql = 'select * FROM mime_types WHERE mime_id = ?';
$res = $db->query($sql, $mime_id);

// Attempt to show the query...
echo $res->getQuery();

// Catch any error and quit
if(DB::isError($res))
{
die("Error");
}

Expected result:
----------------
Suppose that $mime_id has been accidentally (or as a consequence of user input) made empty. I think it would be very helpful if the getQuery() member (especially in such circumstances) was available to report the full query that caused the error.

Actual result:
--------------
In fact although DB::isError() flags this, the line to echo the query has no affect (since it is not a true result object).