Friday, July 7th, 2006
PHP-Based MySQL-to-JSON Converter
<p>A new PHP component by Adnan Siddiqi accepts a MySQL result set and converts it into a JSON message. MySQL To JSON:This class can be used to convert data from MySQL query results into a JavaScript expression in JavaScript Object Notation.
It takes a MySQL query result handle and retrieves the query result column names and the query result data.
The class generates the definition of a JavaScript object in JSON that contains an array of a rows of query result data.
Each array element represents an object with the properties set to the query result column names. The property values are the query results for the respective row and column.
Related Content:











never had a problem there… combine Sajax with PEAR_DB, and you can simply:
function getstuff(){
global $db;
return $db->getAll(‘insert sql string here’);
}
yea this really isn’t news. mybic or any other ajax framework can already do this without having to add anything else.
Just because a library already exists where one solution is employed, don’t dismiss this as being less “newsworthy”. More public resources eqals more options, and more examples of other people’s approaches.
Hi All
First of all Iwould like to thank Michael Mahemoff for mentioning my script.I also thank all people who made comments and rated the class.
Offcourse such feature would be available in different frameworks but I think most of people do not like to setup entire framework for a task of one or two web pages.My class could be useful for such small tasks as well as could be used a complete AJAXised application.
Yes, that’s a great idea to do this. I have included nearly the same in my own class some weeks ago. you can ouput json or xml. You only need a (up to) 2-dimensional array or a mysql result, the rest does the script. problem: different encoding of database and page. to not forget this, you can define the encodings.
look 6 articles below this for “uniAjax”, sorry for ad – but when I read this, I thought “this is exactly what I’ve done and published” recently.
greetz
Andi
Yeah, good to have more choice :)
I am getting javascript error.
Expected “;” at line 44 in jsontest2.html
I am getting javascript error too. I have json.js from http://www.json.org/json.js.
Genereted by OPERA ;
JavaScript – http://localhost/js/json/jsontest2.html
Unknown thread
Error:
name: SyntaxError
message: parseJSON
genereted by IE ;
Exception thrown and not caught
Could you please give me some tips?
Thx, haloki
Excellent web site I will be visiting often
tnxs!