PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Mihajlo Siljanoski   MySQL query, paging and caching helper   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of usage
Class: MySQL query, paging and caching helper
Query and cache MySQL results to be paginated
Author: By
Last change:
Date: 12 years ago
Size: 1,709 bytes
 

Contents

Class file image Download
<?php
require_once("db.class.php");
$sql=new MS_CODE();
$sql->dbhost='localhost';
$sql->dbuser='root';
$sql->dbpass='root';
$sql->dbname='testbase';






//insert example

$for_insert=array(
   
'FIELD_FIRST_NAME'=>'your first name',
   
'FIELD_SECOND_NAME'=>'your second name',
   
'FIELD_AGE'=>55
);


if(
$sql->ms_insert('users',$for_insert)){
    echo
'insert OK';
}
else{
    echo
'FAILED';
}



//delete example

$sql->ms_delete('users',array('FIELD_FIRST_NAME'=>'john','FIELD_SECOND_NAME'=>'smith'));




//update example

$sql->ms_update('users',array('FIELD_FIRST_NAME'=>'Updated first name!'),array('user_id'=>'55'));





//select example

$results=$sql->ms_select("SELECT * FROM users"); //without caching
$results=$sql->ms_select("SELECT * FROM users", true); //with caching

while($row = mysql_fetch_object($results)){
      echo
$row->FIELD_FIRST_NAME.' '.$row->FIELD_SECOND_NAME;
      echo
"<br />";
    }




//custom sql

$m->ms_sql("SELECT * FROM users LIMIT ".@(int)$_GET['mspagestart'].",10");





//example paging

$config = array(
'sql'=>'SELECT * FROM users', //SQL query
'num_link'=>'style="color:#000000; border:1px solid #cccccc; padding:5px 10px 5px 10px;"',
'num_active'=>'style="background-color:#990000; color:#CCCCCC; border:1px solid #cccccc; padding:5px 10px 5px 10px; text-decoration:none;"',
'limit'=>10,
'max_num_render'=>8,
'inner_previous'=>'<span>&laquo;</span>',
'inner_next'=>'<span>&raquo;</span>',
'inner_first'=>'<span>&laquo;&laquo;</span>',
'inner_last'=>'<span>&raquo;&raquo;</span>',
'other_gets'=>'' //other $_GET[] parameters ex. '&city='.$_GET['city'].'&country='.$_GET['country']
);
$sql->ms_paging($config); //this will render the paging here





//HAPPY USING!


?>