Login   Register  
PHP Classes
elePHPant
Icontem

File: mysql2json_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ellery Leung  >  MySQL2JSON  >  mysql2json_example.php  >  Download  
File: mysql2json_example.php
Role: Example script
Content type: text/plain
Description: Class usage
Class: MySQL2JSON
Generate JSON representation from MySQL queries
Author: By
Last change:
Date: 2008-01-30 01:11
Size: 569 bytes
 

Contents

Class file image Download
<?php
include("MYSQL2JSON.class.php");
//MySQL connect
$c mysql_connect("localhost""root""");
mysql_select_db("mysql");

#
#    All JSON syntax are referred in this site:     http://www.json.org/example.html
#

//Start:
$json = new MYSQL2JSON();        //Create an object

print $json->query("SELECT user FROM user WHERE user = 'pma';");
//It will print: {"result": {"user":"pma"}}

print $json->query("SELECT user FROM user;");
//It will print: {"result": [{"user":"civicrm"},{"user":"discuz"},{"user":"drupal"},{"user":"gallery2"},...,{"user":"root"}]}
?>