PHP通过参数来生成MYSQL语句类2008-02-27这个类可以通过具有参数的数组来构建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;
$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 );