无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了php简单操作mysql数据库的类。分享给大家供大家参考。具体如下:
<"_") $prefix .= "_"; $this->prefix = $prefix; } function getLastID() { $id = mysql_fetch_row(mysql_query("SELECT LAST_INSERT_ID()", $this->linkId)); return $id[0]; } function getPossibleValues($tableA, $whereA) { if(gettype($tableA) == "array") { $table = ""; foreach($tableA as $t) { $table .= $this->prefix.$t.", "; } $table = substr($table, 0, -2); } else $table = $this->prefix.$tableA; if(gettype($whereA) != "array") { $whereA = array($whereA); } $return = array(); foreach($whereA as $where) { $sql = mysql_query("SHOW COLUMNS FROM ".$table." LIKE '%".$where."%'"); while($arr = mysql_fetch_array($sql)) { if(strpos($arr['Type'], 'enum')===0) { $vals = substr($arr['Type'], 5, -1); } else { $vals = substr($arr['Type'], 4, -1); } $vals = str_replace("'","",$vals); $vals = explode(",",$vals); $i = 1; foreach($vals as $val) { $return[$arr['Field']][$i++] = $val; } $return[$arr['Field']]['default'] = $arr['Default']; if($arr['Null'] != "NO") $return[$arr['Field']][0] = NULL; } } return $return; } function connect() { $this->linkId = mysql_connect($this->host, $this->user, $this->pass); if(!$this->linkId) { return false; } if(mysql_select_db($this->name, $this->linkId)) return true; mysql_close($this->linkId); return false; } function runSelect($tables, $where = "1", $fieldsA = "*", $order = false, $limit = false, $offset = false, $group = false) { if(gettype($tables) == "array") { $table = ""; foreach($tables as $t) { $table .= $this->prefix.$t.", "; } $table = substr($table, 0, -2); } else $table = $this->prefix.$tables; if(gettype($fieldsA) == "array") { $fields = ""; $keys = array_keys($fieldsA); if($keys[0] != '0') { foreach($keys as $key) { $fields .= $key.' AS '.$fieldsA[$key].', '; } } else { foreach($fieldsA as $field) { $fields .= $field.', '; } } $fields = substr($fields, 0, -2); } else $fields = $fieldsA; $query = "SELECT ".$fields." FROM ".$table." WHERE ".$where. ($order!== false" ORDER BY ".$order:($group!==false " GROUP BY ".$group : "")). ($limit !== false" LIMIT ".$limit:""). ($offset !== false" OFFSET ".$offset:""); return mysql_query($query, $this->linkId); } function runUpdate($table, $valuesA, $where = "1") { if(gettype($valuesA) == "array") { $fields = ""; $values = ""; $keys = array_keys($valuesA); foreach($keys as $key) { if($valuesA[$key] !== NULL) $values .= "`".$key."`='".str_replace("'",'\'', $valuesA[$key])."',"; else $values .= $key."=NULL,"; } $fields = substr($fields, 0, -1); $values = substr($values, 0, -1); } else $values = $valuesA; $query = "UPDATE ".$this->prefix.$table." SET ".$values." WHERE ".$where; if(mysql_query($query, $this->linkId)) return mysql_affected_rows($this->linkId); return false; } function runDelete($table, $where = "1") { if(mysql_query("DELETE FROM ".$this->prefix.$table." WHERE ".$where, $this->linkId)) return mysql_affected_rows($this->linkId); return false; } function runInsert($table, $valuesA, $onDuplicate = NULL) { if(gettype($valuesA) == "array") { $fields = ""; $values = ""; $keys = array_keys($valuesA); foreach($keys as $key) { $fields .= "`".$key."`, "; $values .= ($valuesA[$key]===NULL"NULL, ":"'".str_replace("'", '\'', $valuesA[$key])."', "); } $fields = substr($fields, 0, -2); $values = substr($values, 0, -2); } $onDup = ""; if($onDuplicate != NULL) { $onDup = " ON DUPLICATE KEY UPDATE "; if(gettype($onDuplicate) == "array") { $keys = array_keys($onDuplicate); foreach($keys as $key) { $onDup .= '`'.$key.'`='.($onDuplicate[$key]===NULL"NULL,":"'".str_replace("'", '\'', $onDuplicate[$key])."', "); } $onDup = substr($onDup, 0, -2); } else $onDup .= $onDuplicate; } $query = "INSERT INTO ".$this->prefix.$table.($fields!==NULL"(".$fields.")":""). " VALUES (".$values.")".$onDup; if(mysql_query($query, $this->linkId)) return mysql_affected_rows($this->linkId); return false; } function getCells($table){ $query = "SHOW COLUMNS FROM `".$table."`"; $fields = mysql_query($query, $this->linkId) or die('hej'); return $fields; } function translateCellName($cellName){ $sql = $this->runSelect("mysql_cell_translation","mysql_name = '".$cellName."'"); $row = mysql_fetch_assoc($sql); return $row['human_name']"faded">['.$cellName.']</span>'; } function getError() { return mysql_error($this->linkId); } function close() { mysql_close($this->linkId); } } ?>
希望本文所述对大家的php+mysql数据库程序设计有所帮助。
标签:
php,mysql,数据库类
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年11月14日
2024年11月14日
- 阿杜2024-时光音乐会[金蜂][WAV+CUE]
- 群星《燃!沙排少女 影视原声带》[FLAC/分轨][775.28MB]
- 群星《第6届2010十大发烧唱片精选》2CD [WAV+CUE][1.6G]
- 窦唯1994《黑梦》上海音像首版[WAV分轨][1G]
- 郭子.1996-为爱偷生(载歌载舞歌载戏“极度疯狂”唱作全纪录)【滚石】【WAV+CUE】
- 伍佰.2003-泪桥【艾回】【WAV+CUE】
- 南台湾小姑娘.1996-爱作梦的查某囡仔【大旗】【WAV+CUE】
- 群星《天碟落地-世界[HI-FI] 女声》[WAV分轨][1.1G]
- 黎明《但愿不只是朋友》2022蜚声环球限量版 [WAV+CUE][1G]
- 李玉刚《怀旧辑》玉泽东方[WAV+CUE][1.1G]
- 魔兽世界wlk刺杀贼一键输出宏是什么 wlk刺杀贼一键输出宏介绍
- 魔兽世界wlk战斗贼一键输出宏是什么 wlk战斗贼一键输出宏介绍
- 魔兽世界wlk敏锐贼一键输出宏是什么 wlk敏锐贼一键输出宏介绍
- 李逸朗2007-李威乐[英皇娱乐][WAV+CUE]
- DavidVersace-EyetoEye(2024)[24-44,1]