Tag Archives: debug

How to Dump the Generated Zend_Db SQL Query

The Typical PHP Approach

Typically a PHP programmer will write his SQL query as a string and will execute it via mysql_query.

$sql = "SELECT * FROM my_table";
$resource = mysql_query($sql);

So eventually when you want to dump this “complex” query, or whatever query there is, you can simply “echo” it and see what’s its syntax.

// this query is WRONG because of the where clause
$sql = "SELECT * FROM my_table WHERE id = ";
 
// dump and debug the wrong query
die($sql);
 
// this line won't be executed
$resource = mysql_query($sql);

So far so good, but things appear to be a bit different when you start to work with Zend Framework. Higher levels of abstraction come with slightly more difficult ways to dump (debug) your SQL queries.

OK you’ve two options. Using Zend_Db_Select or … not.
Continue reading How to Dump the Generated Zend_Db SQL Query

Debugging in Zend Framework

Perhaps “debugging” is a bit too strong. However when you’re dumping an array in PHP, you’d probably prefer the print_r or var_dump.

echo '<pre>';
print_r($array);
echo '</pre>';

But did you know that in Zend Framework there’s a built in Zend_Debug?

Zend_Debug::dump($array);

Does pretty much the same thing!

Write human readable debug info!

It’s a common begginer’s developer mistake to write some fullish debug info like “i’m in the IF”, or even worse – “test”. Of course when debugging you don’t get any aditional information. You know only that – you’re in the IF statement!? What a good news! That doesn’t tell you much, isn’t it?

Another bad way to debug is to dump only ids from some database table or loop index. At least write something before that, something like:

alert('on the: ' + index + ' happened something!');

that gives you more and can improve your work so much.