| 
<?
/**
 * This file contain example how to use class mysqlix
 */
 ?>
 <html>
 <body>
 <?
 /**
 * include class mysqlix
 */
 include_once("mysqlix.class.php");
 
 /**
 * Example #1 : Testing constructor mysqlix
 * Look at class documentation to get information on optional paramaters
 */
 echo "<p><b>Tes constructor mysqlix()</b> .... ";
 $con = new mysqlix(); //example of class contructor
 echo "</p>";
 
 /**
 * Example #2 : Testing function drop_db
 * Drop database specified in parameter of function drop_db()
 */
 echo "<p><b>Tes functon drop_db()</b> ....";
 if($con->drop_db('test'))
 echo "success";
 else echo "failed";
 echo "</p>";
 
 /**
 * Example #3 : Testing function create_db
 * Create database with name specified in parameter of function create_db()
 */
 echo "<p><b>Tes function create_db()</b> ...";
 if( $con->create_db('test') )
 echo "success";
 else echo "failed";
 echo "</p>";
 
 $con->select_db('test');
 
 /**
 * Example #4 : Testing function drop_table
 */
 echo "<p><b>Tes functon drop_table()</b> ....";
 if( $con->drop_table('hehe') && $con->drop_table('hoho'))
 echo "success";
 else echo "failed";
 echo "<br>";
 echo "<br>latest statement " . $con->statement . ", lates database $con->latestdb</p>";
 
 
 /**
 * Example  : Testing function create_table, and add_column
 * You can manipulate array column using function add_column
 * In create_table, you define all parameter required
 */
 echo "latest db : $con->latestdb<br>";
 echo "<p><b>Create tables</b>...<br>";
 $arrT = array();
 $arrT = $con->add_column($arrT, 'a', 'INT', null, false, true, true, null, 'this is integer a');
 $arrT = $con->add_column($arrT, 'b', 'VARCHAR', 22, true, false, false, 'gerogero');
 if( $con->create_tables('hehe',$arrT, 'This is comment of table 1') )
 echo "Create table 1 success...<br>";
 else
 echo "Create table 1 failed...<br>";
 echo "<br>latest statement " . $con->statement . "<br>";
 
 $arrT2 = array();
 $arrT2 = $con->add_column($arrT2, 'c', 'VARCHAR', 22, false, false, true, 'gero');
 $arrT2 = $con->add_column($arrT2, 'd', 'VARCHAR', 22, true, false, false, 'gerogero');
 if( $con->create_tables('hoho',$arrT2, 'This is comment of table 2') )
 echo "Create table 2 success...<br>";
 else
 echo "Create table 2 failed...<br>";
 echo "<br>latest statement " . $con->statement . "<br>";
 
 echo "</p>";
 
 /**
 * Example #5 : Testing function create_trigger
 * Creating trigger, for more information, read class documentation
 */
 echo "<p><b>Tes function create_trigger()</b> ....";
 $arr = array("INSERT INTO `hehe` (`a`,`b`) VALUES ('dd','ss')");
 if( $con->create_trigger('triggerring','hoho',$arr,'BEFORE','UPDATE') )
 echo "Successfully creating trigger ";
 else
 echo "Creating trigger aborted. There was error(s)";
 echo "</p>";
 
 echo "latest statement " . $con->statement . "<br>";
 
 /**
 * Example #6 : Testing function drop_trigger
 * Drop a specified name trigger. I don't know why this trigger function can not contain IF EXISTS clause?
 */
 echo "<p><b>Tes function drop_trigger()</b> ....";
 if( $con->drop_trigger('triggerring') )
 echo "success";
 else
 echo "failed";
 echo "</p>";
 
 /**
 * Example #7 : Testing function table_comment
 * Retrieve comment on a table whose name specified in the parameter of function table_comment()
 * Actually, comment is exist on database information_schema
 */
 echo "<p><b>Tes function table_comment()</b> ....";
 echo $con->table_comment('hehe');
 echo "<br>";
 
 /**
 * Example #8 : Testing function table_comments
 * Retrieve comment(s) of each table in a database whose name is specified in the parameter of function table_comments()
 */
 echo "<p><b>Tes function table_comments()</b> ....";
 $rows = $con->table_comments('test');
 echo "<br>";
 foreach($rows as $tupple)
 {
 echo "$tupple[name] => $tupple[comment]";
 echo "<br>";
 }
 echo "</p>";
 
 /**
 * Example #9 : Testing function secure_multi_query
 * Secure your multi query (in array function's parameter) using combination of commit() and rollback()
 */
 echo "<p><b>Tes function secure_multi_query()</b> ....";
 $arr = array("INSERT INTO `hehe` VALUES('hello','world')","INSERT INTO `hoho` VALUES('viva','php')");
 if($con->secure_multi_query($arr))
 echo "secure_multi_query successfully executed";
 else
 echo "There was error(s). But don't worry, the system has been rolled back";
 echo "</p>";
 echo "Latest statement " . $con->statement . "<br>";
 
 /**
 * Example #10 : Testing function insert
 */
 echo "<p><b>Tes function insert() ...";
 if( $con->insert('hehe', array('a' => 'gogo', 'b' =>'gigi')) )
 echo "Data successfully inserted <br>";
 else
 echo "Failed on insert <br>";
 echo "</p>";
 
 /**
 * Example #11 : Testing function update
 * Update database tupple
 * Read class documentation to get more infor
 */
 echo "<p><b>Tes function update()</b> ....";
 if( $con->update('hehe', array('b' =>'gigi'), array('a' => 'hello')) )
 echo "Data successfully updated <br>";
 else
 echo "Failed on update <br>";
 echo "</p>";
 
 /**
 * Example #12 : Testing function select
 * look at : array('a' => 'hello','b' => '')
 * note : 'a' and 'b' is columns that you want to be retrieved,
 * 'hello' is the value of column 'a' in where clause, because value of 'b' is '', so column 'b' doesn't included in where clause
 */
 echo "<p><b>Tes function select()</b> ";
 //$con->query("use test");
 echo "<br>";
 $result = $con->select('hehe', array('a' => 'hello','b' => ''));
 echo $con->statement . "<br>";
 while($row = $result->fetch_row())
 {
 echo "$row[0] = $row[1]";
 echo "<br>";
 }
 echo "</p>";
 //here destructor will be called automatically
 ?>
 </body>
 </html>
 |