Php implements simple Mysql operations. phpmysql_PHP tutorial

Source: Internet
Author: User
Php implements the simple Mysql operation class, phpmysql. Php implements a simple Mysql operation class. The simple Mysql operation class encapsulated by phpmysql is already written in the Ben framework based on PDO. the code style is somewhat non-invasive... Mysql. class. php implements simple Mysql operation class, phpmysql

The simple Mysql operation class encapsulated by myself has been written in the Ben framework based on PDO, and the code style has no headers...

Mysql. class. php

<?phpclass mysql extends PDO{  public $server;  public $database;  public $user;  public $password;  public $sql;  public function __construct($server,$database,$user,$password,$port=3306){    $this->server = $server;    $this->database = $database;    $this->user = $user;    $this->password = $password;    parent::__construct("mysql:host=$server;port=$port;dbname=$database",$user,$password);    $this->query('SET NAMES utf8');  }  public function drop($table){    $sql = 'DROP TABLE '.$table.';';    $re = $this->query($sql);    if($re){      return true;    }else{      return false;    }  }  public function insert($table,$name,$value=null){    $sql = "INSERT INTO ".$table.'(';    if($value == null){    $arrname = array_keys($name);    $arrvalue = array_values($name);    }else{    $arrname = explode('|', $name);    $arrvalue = explode('|', $value);    }    for($i=0;$i
 
  query($sql);    if($re){      return true;    }else{      return false;    }  }  public function delete($table,$Conditionsname,$Conditionsvalue=null){    if($Conditionsvalue!=null){      $sql = "DELETE FROM ".$table." WHERE ".$Conditionsname."='".$Conditionsvalue."';";    }else{      $sql = "DELETE FROM ".$table." WHERE ";      $arrname = array_keys($Conditionsname);      $arrvalue = array_values($Conditionsname);      for($i=0;$i
  
   query($sql);    if($re){      return true;    }else{      return false;    }  }  public function select($table,$name,$Conditionsname,$Conditionsvalue=null){    if($Conditionsvalue!=null){      $sql = "SELECT ".$name." FROM ".$table." WHERE ".$Conditionsname."='".$Conditionsvalue."';";    }else{      $sql = "SELECT ".$name." FROM ".$table." WHERE ";      $arrname = array_keys($Conditionsname);      $arrvalue = array_values($Conditionsname);      for($i=0;$i
   
    query($sql);    $row = $re->fetch();    return $row[$name];  }  public function update($table,$name,$value,$Conditionsname,$Conditionsvalue=null){    if($Conditionsvalue!=null){      $sql = "UPDATE ".$table." SET ".$name."= '".$value."' WHERE ".$Conditionsname."='".$Conditionsvalue."';";    }else{      $sql = "UPDATE ".$table." SET ".$name."= '".$value."' WHERE ";      $arrname = array_keys($Conditionsname);      $arrvalue = array_values($Conditionsname);      for($i=0;$i
    
     query($sql);    if($re){      return true;    }else{      return false;    }  }  public function group($table,$name){    $sql = "SELECT ".$name." FROM ".$table.";";    $return = array();    $re = $this->query($sql);    while($row = $re->fetch(PDO::FETCH_ASSOC)){      array_push($return,$row[$name]);    }    return $return;  }  public function fetchall($sql){    $return = array();    $re = $this->query($sql);    while($row = $re->fetch(PDO::FETCH_ASSOC)){      array_push($return,$row);    }    return $return;  }}
    
   
  
 

The simple Mysql operation class encapsulated by the hacker itself has been written in the Ben framework based on PDO, and the code style has no headers... Mysql. class. php...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.