自己封装的mysql简易操作类,已塞在ben框架中,基于pdo来写的,,代码风格上有些无厘头。。。
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;$iquery($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;$iquery($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;$iquery($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; }}
