巅云智能建站平台搭建版(创业流派版)火爆上线,毕生受权!新增:文章智能收罗+全站真静态打包+都会分站+智能小法式+不法词过滤+H5自顺应+智能链词等功效功效概况
建站专提News

php简略操纵mysql数据库的类

一佰互联网站开辟设想(www.taishanly.com) 宣布日期 2020-04-28 13:45:25 阅读数: 116

本文实例报告了php简略操纵mysql数据库的类。分享给大师供大师参考。详细以下:

<?php/** * Database class * * @version: 2.2 * @revised: 27 may 2007 * **/class Database { var $host; var $name; var $user; var $pass; var $prefix; var $linkId; function Database($mysql) {  foreach($mysql as $k => $v){   $this->$k = $v;  }  if(strlen($this->prefix)>0 && substr($this->prefix, -1) !== "_")  $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"]?$row["human_name"]:"<span class="faded">[".$cellName."]</span>"; } function getError() {  return mysql_error($this->linkId); } function close() {  mysql_close($this->linkId); }}?>

但愿本文所述对大师的php+mysql数据库法式设想有所赞助。

一佰互联是天下着名建站品牌办事商,咱们有九年、网站建造、网页设想、php开辟和域名注册及假造主机办事经历,供给的办事更是天下着名。最近几年来还整合团队上风自立开辟了可视化多用户”“3.0平台版,拖拽排版网站建造设想,轻松完成pc站、手机微网站、小法式、APP一体化全网营销网站扶植 ,已胜利的为天下上百家收集公司供给自助建站平台搭建办事。更多资讯:tags标签

相干消息more

14
04月
若何能力做好网站优化计划

跟着网站优化的成长,愈来愈多的企业起头正视网站优化,也起头做网站优化,一局部企业在做网站优化之前,但愿网站优化公司供给一个网站优化计划,出格... >>概况

27
04月
在Yii2中利用Pjax致使Yii2内联剧本

当我用defunkt/jquery-pjax载入Yii2的ActiveForm时发生一个毛病,一般环境下是ActiveForm的两个js应当... >>概况

04
04月
黑客一旦获得数据后接纳哪些体例来变现的?

简介:黑客一旦获得数据后接纳哪些体例来变现?是一些伴侣们比拟感乐趣的,业内相干专家先容,常常接纳的体例有以下这些: 体例一:成立数据存储库出... >>概况

25
04月
PHP+jQuery完成即点即改功效示例

本文实例报告了PHP+jQuery完成即点即改功效。分享给大师供大师参考,详细以下:<!DOCTYPE html><htm... >>概况

高端网站扶植

美工统筹SEO,为企业电子商务营销助力!

德律风:

023-85725751
建站

产物

域名注册 假造主机 云办事器 企业邮局
智能建站 APP打包 微站/小法式 创业平台
网站推行 媒体营销 智能收罗 AI机械人
400德律风 短信营销 店销机械人
私家定制 流派网站