MySQL 2 JSON converter|MySQL till JSON konverterare

April 29, 2009

Javascript, PHP

MySQL 2 JSON är en enkel PHP klass som genererar JSON kod utifrån en MySQL fråga. Den tar en MySQL fråga och skapar helt enkelt en JSON sträng innehållande alla rader från frågan.
MySQL 2 JSON is a basic PHP class that Generate JSON output from MySQL query results. It takes an handle of a previously executed MySQL database query and retrieves the results to generate a JSON string with the values of all the result rows.

ExempelSample:

<?PHP

//include the mysql_to_json class
include(‘mysql_to_json.class.php’);

//Mysql stuff.
mysql_connect(‘host’, ‘username’, ‘password’);
mysql_select_db(‘users’);
$query = mysql_query(‘SELECT * FROM users’);

//Now mysql_to_json supports many methods of getting from your query to the json output, I will show you 2 methods

/////////////////////////////////////
// METHOD 1 – Using constructor //
///////////////////////////////////

//create a new instance of mysql_to_json
$mtj = new mysql_to_json($query, ‘cbfunc’);

//show the json output
echo $mtj->get_json();

///////////////////////////////////////
// METHOD 2 – Using method chaining //
/////////////////////////////////////

//create a new blank instance of mysql_to_json
$mtj = new mysql_to_json();

//show the json output through method chain
echo $mtj->set_query($query)->set_cbfunc(‘cbfunc’)->get_json();

?>

Ladda nerDownload: MySQL to json 2009-04-22

, ,