Location: PHPKode > scripts > MySQL 2 JSON > mysql-2-json/example.php
<?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();

?>
Return current item: MySQL 2 JSON