Re: DB_DataObjects Debugging: How do I get the raw sql string created by a dataobjects method?
| From: | Markus Wolff | Date: | Wed, 19 Apr 2006 19:20:14 +0000 |
| Subject: | Re: DB_DataObjects Debugging: How do I get the raw sql string created by a dataobjects method? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23760@lists.php.net to get a copy of this message | ||
Am Wednesday 19 April 2006 20:55 schrieb Clements, Brent M (SAIC):
> Ok Guys, I figured out how to get the sql used.
>
> After you execute a $obj->find() method call,
>
> just var_dump the $obj and you'll get a string variable called
> "query" that shows the RAW SQL Statement
>
> Good luck to everyone
No luck needed. You're doing it wrong.
This piece of code:
DB_DataObject::debugLevel(1);
$cat =& DB_DataObject::factory('Glr_category');
$cat->orderBy('sort_rank');
$cat->find();
...will output the following:
Glr_category: __find:
Glr_category: QUERY: SELECT * FROM glr_category ORDER BY sort_rank
Glr_category: query: QUERY DONE IN 0.00110697746277 seconds
If you set the debug level higher than 1, you'll get even more output.
If you want the raw SQL query *in a clean way*, you can do something
like this:
var_dump($cat->getDatabaseConnection()->last_query);
...or, if you're using PHP4:
$connection = $cat->getDatabaseConnection();
var_dump($connection->last_query);
CU
Markus