国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP實現的構造sql語句類實例

2024-05-04 23:42:43
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了PHP實現的構造sql語句類,結合實例形式分析了PHP針對常用SQL語句的動態構造與生成技巧,需要的朋友可以參考下
 

本文實例講述了PHP實現的構造sql語句類。分享給大家供大家參考,具體如下:

/*** @package Database Class* @author injection (mail:injection.mail@gmail.com)* @version 1.0*/@ini_set( 'display_errors',0 );class DataBase{ private $mDb_host,$mAb_user,$mAb_pwd,$mConn_No; function DataBase( $Conn_Obj ){ $this->connectDb( $Conn_Obj ); } function connectDb( $Conn_Obj ){ $this->mDb_host = $Conn_Obj->host; $this->mAd_name = $Conn_Obj->user; $this->mAd_pwd = $Conn_Obj->pwd; $this->mConn_No = mysql_connect( $this->mDb_host, $this->mAd_name, $this->mAd_pwd ); } function selectDb( $Conn_Obj ){ $this->mDb_name = $Conn_Obj->dbname; mysql_select_db( $this->mDb_name ); }}/*** @package Making Sqls Class exetends Database Class* @author injection (mail:injection.mail@gmail.com)* @version 1.0*/class MakeSql extends DataBase{ private $mSql; function MakeSql( $type,$arr_colum_list, $arr_sql_choice ){ $this->MakeSqlType( $arr_colum_list, $arr_sql_choice ); } //switch make list function MakeSqlType( $type, $arr_colum_list, $arr_sql_choice ){ switch( $type ){ case 'insert': return $this->makeInsert( $arr_colum_list, $arr_sql_choice ); case 'select': return $this->makeSelect( $arr_colum_list, $arr_sql_choice ); case 'update': return $this->makeUpdate( $arr_colum_list, $arr_sql_choice ); case 'delete': return $this->makeDelete( $arr_colum_list, $arr_sql_choice ); } } //make insert function makeInsert( $arr_colum_list,$arr_sql_choice ){ $colum_key = array_keys( $arr_colum_list ); $colum_value = array_values( $arr_colum_list ); $this->mSql = "INSERT INTO ".$arr_sql_choice["tbl_name"]."( ".join( ',' , $colum_key )." ) VALUES( '".join( "','" , $colum_value )."')"; return $this->mSql; } //making select function makeSelect( $arr_colum_list = '*' , $arr_sql_choice ){ $colum_value = array_keys( $arr_colum_list ); foreach( $arr_sql_choice as $sql_key => $sql_value ){ if( strcmp( $sql_key, 'tbl_name' ) == 0 ){ if( strcmp($arr_colum_list, '*' ) !== 0 )  $this->mSql = "SELECT ".join( ',' , $colum_value )." FROM ".$sql_value; else  $this->mSql = "SELECT * FROM ".$sql_value; } else if( strcmp( $sql_value, '' ) !== 0 )  if(strcmp( $sql_key, 'WHERE' ) === 0 && strcmp( $sql_value, 'colum' ) === 0 ){  foreach($arr_colum_list As $colum_key => $colum_value )  $this->mSql .= "$colum_key = '$colum_value' AND ";  $this->mSql = rtrim( $this->mSql, " AND " );  }  else  $this->mSql .= " $sql_key ".$sql_value; } return $this->mSql;  } //making update  function makeUpdate( $arr_colum_list, $arr_sql_choice ){ $this->mSql = "UPDATE ".$arr_sql_choice['tbl_name']." SET "; foreach( $arr_colum_list as $colum_key => $colum_value ) $this->mSql .= "$colum_key = '$colum_value',"; $this->mSql = rtrim( $this->mSql , ','); foreach( $arr_sql_choice as $sql_key => $sql_value ){ if( strcmp( $sql_value, '' ) !== 0 && strcmp( $sql_key, 'tbl_name' ) !==0 && strcmp( $sql_key, 'ORDER BY' ) !== 0 )  $this->mSql .= " $sql_key ".$sql_value; } return $this->mSql; } //making delete function makeDelete( $arr_colum_list, $arr_sql_choice ){ $this->mSql = "DELETE FROM ".$arr_sql_choice['tbl_name']; foreach( $arr_sql_choice as $sql_key => $sql_value ){ if( strcmp( $sql_key, 'tbl_name' ) !== 0 && strcmp( $sql_value, '' ) !== 0 ){ $this->mSql .= " $sql_key ".$sql_value; } } return $this->mSql; }}

 

希望本文所述對大家PHP程序設計有所幫助。



注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 银川市| 石棉县| 收藏| 黄龙县| 西平县| 梁平县| 新源县| 乡城县| 昭觉县| 庄河市| 河东区| 昆山市| 吕梁市| 海原县| 竹溪县| 宜兰县| 高要市| 长治市| 孝感市| 白朗县| 行唐县| 多伦县| 新田县| 康马县| 博客| 五河县| 郓城县| 凭祥市| 绵阳市| 当阳市| 营口市| 疏勒县| 科技| 延安市| 钟山县| 临海市| 延长县| 涞水县| 西平县| 思茅市| 长海县|