浅谈PHP值mysql操作类.doc
文本预览下载声明
浅谈PHP值mysql操作类
“数据库连接错误”.mysqli_connect_errno();
nbsp; nbsp; nbsp; exit();
nbsp; nbsp; }
nbsp; nbsp; $this-db-query(“set names utf8”);
nbsp; nbsp; $this-table=$table_names;
nbsp; nbsp; $this-opt[‘field’]=“*”;
nbsp; nbsp; $this-opt[‘where’]=$this-opt[‘Order’]=$this-opt[‘Limit’]=$this-opt[‘Group’]=‘‘;
// nbsp; nbsp;var_dump($this-opt[‘where’]);
nbsp; nbsp; //$this-M($table_names);
nbsp; }
nbsp; //数据库连接
// nbsp;protected function M($table_name){
// nbsp; nbsp;$this-db=new mysqli(DBHOST,DBUSER,DBPWD,DBNAME);
//
// nbsp; nbsp;if(mysqli_connect_errno()){
// nbsp; nbsp; nbsp;echo “数据库连接错误”.mysqli_connect_errno();
// nbsp; nbsp; nbsp;exit();
// nbsp; nbsp;}
// nbsp; nbsp;$this-db-query(“set names utf8”);
// nbsp; nbsp;$this-table=$table_name;
// nbsp;}
nbsp; //表中的字段
nbsp; public function tbField(){
nbsp; nbsp; $desc=$this-db-query(“DESC {$this-table}”);
nbsp; nbsp; $fieldArr=array();
nbsp; nbsp; while(($row=$desc-fetch_assoc())!=false){
nbsp; nbsp; nbsp; $fieldArr[]=$row[‘Field’];
nbsp; nbsp; }
nbsp; nbsp; // var_dump($fieldArr);
nbsp; nbsp; return $fieldArr;
nbsp; }
nbsp; //查询字段
nbsp; public function field($filed){
nbsp; nbsp; //拆分字段
nbsp; nbsp; $filedArr=is_string($filed)?explode(“,”,$filed):$filed;
nbsp; nbsp; if(is_array($filedArr)){
nbsp; nbsp; nbsp; $filed=‘‘;
nbsp; nbsp; nbsp; foreach($filedArr as $v){
nbsp; nbsp; nbsp; nbsp; $filed.=“‘“.$v.”‘“.”,”;
nbsp; nbsp; nbsp; }
nbsp; nbsp; }
nbsp; nbsp; //var_dump($filed);
nbsp; nbsp; return rtrim($filed,”,”);
nbsp; }
nbsp; //判断字段是否存在
nbsp; public function isfield($fileds)
nbsp; {
nbsp; nbsp; $filedArr=is_string($fileds)?explode(“,”,$fileds):$fileds;
nbsp; nbsp; $tbFiled=$this-tbField();
nbsp; nbsp; //var_dump( $tbFiled);
nbsp; nbsp; foreach($filedArr as $v){
nbsp; nbsp; nbsp; if(!in_array($v,$tbFiled)){
nbsp; nbsp; nbsp; nbsp; nbsp;echo “字段输入发错”;
nbsp; nbsp; nbsp; }
nbsp; nbsp; }
nbsp; }
nbsp; //条件语句
nbsp; publi
显示全部