PHP通过参数来生成MYSQL语句类

时间:2010-01-20 08:24:44  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:句。   例子:    <? php    /* *******************************************************************   Example file   This example shows how to use the MyLibSQLGen class      The example is based on the following MySQL table:   
  正文:

这个类可以通过具有参数的数组来构建mysql查询语句。
  这个类可以通过指定的表和字段参数创建SELECT ,INSERT , UPDATE 和 DELETE 语句。
  这个类可以创建SQL语句的WHERE条件,像LIKE的查询语句,使用LEFT JOIN和ORDER 语句。
  例子:
   <? PHP
   /* *******************************************************************
  Example file
  This example shows how to use the MyLibSQLGen class
  
  The example is based on the following MySQL table:
  
  CREATE TABLE customer (
   id int(10) unsigned NOT NULL auto_increment,
   name varchar(60) NOT NULL default '',
   address varchar(60) NOT NULL default '',
   city varchar(60) NOT NULL default '',
   PRIMARY KEY (cust_id)
  ) TYPE=MyISAM;
  
  ******************************************************************* */
  
   require_once ( " class_mylib_SQLGen-1.0.php " );
  
   $fields = Array ( " name " , " address " , " city " );
   $values = Array ( " Fadjar " , " Resultmang Raya Street " , " Jakarta " );
   $tables = Array ( " customer " );
  
   echo " <b>Result Generate Insert</b><br> " ;
   $object = new MyLibSQLGen();
   $object -> clear_all_assign(); // to refresh all property but it no need when first time execute
   $object -> setFields( $fields );
   $object -> setValues( $values );
   $object -> setTables( $tables );
  
   if ( ! $object -> getInsertSQL()){ echo $object -> Error; exit ;}
   else { $sql = $object -> Result; echo $sql . " <br> " ;}
  
  
   echo " <b>Result Generate Update</b><br> " ;
   $fields = Array ( " name " , " address " , " city " );
   $values = Array ( " Fadjar " , " Resultmang Raya Street " , " Jakarta " );
   $tables = Array ( " customer " );
   $id = 1 ;
   $conditions [ 0 ][ " condition " ] = " id='$id' " ;
   $conditions [ 0 ][ " connection " ] = "" ;
  
   $object -> clear_all_assign();
   $object -> setFields( $fields );
   $object -> setValues( $values );
   $object -> setTables( $tables );
   $object -> setConditions( $conditions );
  
   if ( ! $object -> getUpdateSQL()){ echo $object -> Error; exit ;}
   else { $sql = $object -> Result; echo $sql . " <br> " ;}
  
   echo " <b>Result Generate Delete</b><br> " ;
   $tables = Array ( " customer " );
   $conditions [ 0 ][ " condition " ] = " id='1' " ;
   $conditions [ 0 ][ " connection " ] = " OR " ;
   $conditions [ 1 ][ " condition " ] = " id='2' " ;
   $conditions [ 1 ][ " connection " ] = " OR " ;
   $conditions [ 2 ][ " condition " ] = " id='4' " ;
   $conditions [ 2 ][ " connection " ] = "" ;
  
   $object -> clear_all_assign();
PHP通过参数来生成MYSQL语句类》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/PHP/12075.html

 1/7    1 2 3 4 5 6 下一页 尾页


关键字:

关于《PHP通过参数来生成MYSQL语句类》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td