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


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.

3 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!

  2. Love your stuff. I hope to come out and lift with you in Texas. Not sure when. I am a sophmore in high school in Arizona, a start at olb for the varsity football team at Westwood High School, hoping to make it to a Division 1 college. Keep up your posts. They are extremely helpful. Muslim Personal Trainer

Leave a Reply

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