您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php实现Mysql简易操作类

2025/4/22 3:06:19发布26次查看
这个php实现的mysql的操作类完整版已经使用过了,而这个简化版是经过修改完整版后的简化版,适用在一般的 php 应用中,功能上可以实现基本的增删改查的操作,以
自己封装的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; }}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product