Using PHP’s var_dump() to Display SQL Query Results

Using the power of PHP’s var_dump() displays structured information about one or more expressions that includes its type and value. By definition var_dump() is a debugging tool, which displays structured information about any PHP variable. Below is a handy bit of code using var_dump() to test and verify that a SQL query contains data and view the contents using PHP:


$sql = mysql_query("SELECT * FROM your_table WHERE key = 'value'");
$assoc = mysql_fetch_assoc($sql);

// Dump variable containing the result of the MySQL query
var_dump($assoc);

VICTORY!

This was a pretty simple example for exporting the results of a SQL query using vardump(). Using this bit of code we will receive structured information about our SQL query that includes its types and values.

5 thoughts on “Using PHP’s var_dump() to Display SQL Query Results

  1. Thanks for posting this. I have been trying to figure out how to display all the results of a mysql query all morning with no luck. Just want to make sure I’m getting back what I’m expecting!

Leave a Reply

Your email address will not be published. Required fields are marked *