新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇文章给大家分享的是有关使用php怎么不行一个Mysql操作类,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
成都创新互联于2013年开始,先为荥经等服务建站,荥经等地企业,进行企业商务咨询服务。为荥经企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。mysql.class.php
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;$iquery($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; } }
以上就是使用php怎么不行一个Mysql操作类,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。