开发者

Print an SQL Query in PHP so it is 'human readable'

开发者 https://www.devze.com 2023-03-07 05:58 出处:网络
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.)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号