Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Luke Szanto  >  MySQL 2 JSON  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example, shows 2 methods of using mysql 2 json
Class: MySQL 2 JSON
Generate JSON output from MySQL query results
Author: By
Last change: The script has been updated, now accepts the query string rather than the mysql_query() result.
Date: 2009-05-02 01:03
Size: 1,262 bytes
 

Contents

Class file image Download
<?php

/*/ ---- UPDATE ---- //

mysql_to_json now executes the query inside of the class so you simply pass the query string to the class when
you set the query. Please make sure you have filtered the query strings before hand to protect yourself from 
injection as this class has no such features at this current time.

// ---- Update ---- /*/

//include the mysql_to_json class
include('mysql_to_json.class.php');

//Mysql stuff.
mysql_connect('localhost''root''loel');
mysql_select_db('prohostcp');

//create a query string to use
$query 'SELECT * FROM employees';

//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);

//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('loels')->get_json();

?>