PHP implementation MySQL simple operation class, phpmysql_php tutorial

Source: Internet
Author: User

PHP implements MySQL easy-to-operate class, Phpmysql


Your own packaged MySQL easy-to-operate class, which has been plugged into Ben's frame, is based on PDO, and the code is somewhat nonsensical ...

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;p ort= $port;d bname= $database", $user, $password);  $this->query (' SET NAMES utf8 ');    The 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 = "DE Lete 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; }}

     
    
   
  
 

http://www.bkjia.com/PHPjc/1060091.html www.bkjia.com true http://www.bkjia.com/PHPjc/1060091.html techarticle PHP Implementation of the MySQL simple Operation class, phpmysql their own packaged MySQL simple Operation class, has been stuffed in Ben Frame, based on PDO to write, the code style is somewhat unreasonable ... 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.