php简洁操作mysql数据库的类_

php简洁操作mysql数据库的类_

ID:63497734

大小:13.32 KB

页数:10页

时间:2021-08-24

php简洁操作mysql数据库的类__第1页
php简洁操作mysql数据库的类__第2页
php简洁操作mysql数据库的类__第3页
php简洁操作mysql数据库的类__第4页
php简洁操作mysql数据库的类__第5页
资源描述:

《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".

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。