PHP PROJECT

README.md

Add, List, Edit and Delete

Add, List, Edit and Delete records in MySQL tables. It can connect to a MySQL database using MySQLi and generate listing of records of a database table with support to paginate the listings with a limited amount of records.

Files


NameTypeSizeLast Modified
aed-pager-class.php phpfile icon 2328 11 November 2015 10:49:52
aed-example.php phpfile icon 3163 11 November 2015 10:49:52
aed-config.php phpfile icon 462 11 November 2015 10:49:52
aed.sql sqlfile icon 263 11 November 2015 10:49:52
aed-class.php phpfile icon 2924 11 November 2015 10:49:52
aed-template.htm textfile icon 1685 11 November 2015 10:49:52

Source

  1. <?
  2. /**
  3.  * PHP ADD EDIT DELETE Class
  4.  * @author admin@v23.in - http://v23.in
  5.  * @version 1.0.0
  6.  * @date October 21, 2015
  7. */
  8. class aed extends mysqli {
  9. public    $affected_rows 0;
  10. private    $link_id 0;
  11. private    $query_id 0;
  12. public    $error "";
  13.     public function __construct($host$user$pass$db) {
  14.         parent::__construct($host$user$pass$db);
  15.         if (mysqli_connect_error()) {
  16.             die('Connect Error (' mysqli_connect_errno() . ') '
  17.                     mysqli_connect_error());
  18.         }
  19.     }
  20.     
  21.     public function query2($sql){
  22.     $this->query_id $this->query($sql);
  23.     if (!$this->query_id){
  24.     return 0;
  25.     }
  26.     return $this->query_id;
  27.     }    
  28.     
  29.     public function query2row($sql){
  30.     $this->query_id $this->query($sql);
  31.     if($this->query_id->num_rows 0){
  32.             return $this->query_id->fetch_assoc();
  33.         }
  34.     else
  35.     return false;    
  36.     }    
  37.     
  38.     public function check($tablename,$data){
  39.         foreach ($data as $k=>$v)
  40.             {
  41.             isset($vals) ? $vals .= ' AND ' $vals '';
  42.             $vals .= $k." = '".$this->real_escape_string($v)."'";
  43.             }
  44.     $sql "SELECT * FROM $tablename WHERE $vals";        
  45.     $this->query_id $this->query($sql);
  46.     if($this->query_id->num_rows 0){
  47.     return "Already Exist";
  48.     }
  49.     else
  50.     return false;
  51.     }    
  52.     
  53.     public function insert($table,$data){
  54.         $cols implode(','array_keys($data));
  55.             foreach (array_values($data) as $value)
  56.             {
  57.             isset($vals) ? $vals .= ',' $vals '';
  58.             $vals .= '\''.$this->real_escape_string($value).'\'';
  59.             }
  60.         return $this->query('INSERT INTO '.$table.' ('.$cols.') VALUES ('.$vals.')');
  61.         }
  62.     
  63.     public function update($table,$data,$where){
  64.         
  65.             foreach ($data as $k=>$v)
  66.             {
  67.             isset($vals) ? $vals .= ',' $vals '';
  68.             $vals .= '`'.$k.'` = \''.$this->real_escape_string($v).'\'';
  69.             }
  70.             
  71.         return $this->query('UPDATE '.$table.' SET '.$vals.' WHERE '.$where.'');
  72.         }
  73.         
  74.     public function delete($table,$where){
  75.         return $this->query('DELETE FROM '.$table.'  WHERE '.$where.' ');
  76.         }    
  77.     
  78.     public function totalPage($sql) {
  79.         $sql="SELECT SQL_CALC_FOUND_ROWS * FROM $sql LIMIT 1";
  80.         $temp =$this->query($sql);
  81.         $result =$this->query("SELECT FOUND_ROWS()");
  82.         $total mysqli_fetch_row($result);
  83.         mysqli_free_result($result);
  84.         return $total[0];
  85.         }
  86.         
  87.     public function makeTTArray($table)
  88.     {
  89.     $data=$this->getField($table);
  90.     $t=array();
  91.     foreach($data['name'] as $key=>$value){
  92.     $t[$value]= '';
  93.     }
  94.     return $t;
  95.     }
  96.     public function getField($table)
  97.     {
  98.     $meta=0;
  99.     $meta = array('type'=>'','name'=>'','len'=>'','flags'=>'');
  100.     $sql="SELECT * FROM $table;";
  101.         if($this->query_id $this->query($sql)){
  102.             while ($finfo mysqli_fetch_field($this->query_id)) {
  103.             $meta['type'][]=$finfo->type;
  104.             $meta['name'][]=$finfo->name;
  105.             $meta['flags'][]=$finfo->flags;
  106.             }
  107.         mysqli_free_result($this->query_id);    
  108.         }
  109.         else
  110.         return 0;
  111.     return $meta;
  112.     }
  113. }
  114. ?>

Demo

You can find a demo available here: aed

Requirment

  • mySql
  • PHP >= 5.4
  • Apache Server

Contribute

  • Vishv Sahdev

Example

>>

Download