"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Convert PHP Database Result Arrays to JSON?

How to Convert PHP Database Result Arrays to JSON?

Published on 2024-11-08
Browse:154

How to Convert PHP Database Result Arrays to JSON?

Converting PHP Database Result Arrays to JSON

You want to convert the result array of a database query to JSON format in PHP. The following code retrieves a row from the database:

$row = mysql_fetch_array($result);

To convert the $row array to JSON format for use with jQuery plugins, you can utilize the json_encode function:

echo json_encode($row);

Note that json_encode is only available in PHP version 5.2.0 and above. If you are using an earlier PHP version, you may need to use a third-party library or write your own JSON encoding function.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3