Print an SQL Query in PHP so it is 'human readable'
Is there a way of printing a result from an sql query ra开发者_如何学Gother than just reading a resource id? Something like the way 'print_r' works?
(Assuming MySQL.)
There is no native PHP functionality to iterate a resultset through a resource handle, no. You must iterate yourself using mysql_fetch_assoc
.
On the upside, you can write a function to do it.
function print_rs($recordset) {
while ($row = $recordset->fetch_assoc())
print_r($row);
}
print_rs($db->query("SELECT * FROM `lol`"));
.. or something along these lines.
Are you printing the return value of mysql_connect
? You should be looking in the output of mysql_fetch_assoc
instead.
精彩评论