How do I use the json_encode()
function with MySQL query results? Do I need to iterate through the rows or can I just apply it to the entire results object?
相关问题
- Views base64 encoded blob in HTML with PHP
- Jackson Deserialization not calling deserialize on
- Laravel Option Select - Default Issue
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
I have the same requirement. I just want to print a result object into JSON format so I use the code below. I hope you find something in it.
http://www.php.net/mysql_query says "
mysql_query()
returns a resource".http://www.php.net/json_encode says it can encode any value "except a resource".
You need to iterate through and collect the database results in an array, then
json_encode
the array.