资源描述:
《php简洁操作mysql数据库的类_》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、php简洁操作mysql数据库的类_具体如下:?php/***Databaseclass**@version:2.2*@revised:27may2021***/classDatabase{var$host;var$name;var$user;var$pass;var$prefix;var$linkId;functionDatabase($mysql){foreach($mysqlas$k=$v){$this-$k=$v;}if(strlen($this-prefix)0substr($this-prefix,-1)!=="_")$prefix.="_";$this-prefix=$prefi
2、x;}functiongetLastID(){$id=mysql_fetch_row(mysql_query("SELECTLAST_INSERT_ID()",$this-linkId));return$id[0];}functiongetPossibleValues($tableA,$whereA){if(gettype($tableA)=="array"){$table="";foreach($tableAas$t){$table.=$this-prefix.$t.",";}$table=substr($table,0,-2);}else$table=$this-prefix.$table
3、A;if(gettype($whereA)!="array"){$whereA=array($whereA);}$return=array();foreach($whereAas$where){$sql=mysql_query("SHOWCOLUMNSFROM".$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,-
4、1);}$vals=str_replace("'","",$vals);$vals=explode(",",$vals);$i=1;foreach($valsas$val){$return[$arr['Field']][$i++]=$val;}$return[$arr['Field']]['default']=$arr['Default'];if($arr['Null']!="NO")$return[$arr['Field']][0]=NULL;}}return$return;}functionconnect(){$this-linkId=mysql_connect($this-host,$t
5、his-user,$this-pass);if(!$this-linkId){returnfalse;}if(mysql_select_db($this-name,$this-linkId))returntrue;mysql_close($this-linkId);returnfalse;}functionrunSelect($tables,$where="1",$fieldsA="*",$order=false,$limit=false,$offset=false,$group=false){if(gettype($tables)=="array"){$table="";foreach($t
6、ablesas$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($keysas$key){$fields.=$key.'AS'.$fieldsA[$key].',';}}else{foreach($fieldsAas$field){$fields.=$field.',';}
7、}$fields=substr($fields,0,-2);}else$fields=$fieldsA;$query="SELECT".$fields."FROM".$table."WHERE".$where.($order!==false?"ORDERBY".$order:($group!==false?"GROUPBY".$group:"")).($limit!==false?"LIMIT".