搜索
查看: 2682|回复: 0

PHP实现的通过参数生成MYSQL语句类完整实例

[复制链接]

4856

主题

4856

帖子

4861

积分

新手上路

Rank: 1

积分
4861
发表于 2018-2-11 12:12:56 | 显示全部楼层 |阅读模式

            本文实例讲述了PHP实现的通过参数生成MYSQL语句类。分享给大家供大家参考,具体如下:
这个类可以通过指定的表和字段参数创建SELECT ,INSERT , UPDATE 和 DELETE 语句。
这个类可以创建SQL语句的WHERE条件,像LIKE的查询语句,使用LEFT JOIN和ORDER 语句
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 . "
" ;}
echo  " Result Generate Update
" ;
$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 . "
" ;}
echo  " Result Generate Delete
" ;
$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();
$object -> setTables( $tables );
$object -> setConditions( $conditions );
if ( ! $object -> getDeleteSQL()){ echo  $object -> Error; exit ;}
else { $sql = $object -> Result; echo  $sql . "
" ;}
echo  " Result Generate List
" ;
$fields = Array ( " id " , " name " , " address " , " city " );
$tables = Array ( " customer " );
$id = 1 ;
$conditions [ 0 ][ " condition " ] = " id='$id' " ;
$conditions [ 0 ][ " connection " ] = "" ;
$object -> clear_all_assign();
$object -> setFields( $fields );
$object -> setTables( $tables );
$object -> setConditions( $conditions );
if ( ! $object -> getQuerySQL()){ echo  $object -> Error; exit ;}
else { $sql = $object -> Result; echo  $sql . "
" ;}
echo  " Result Generate List with search on all fields
" ;
$fields = Array ( " id " , " name " , " address " , " city " );
$tables = Array ( " customer " );
$id = 1 ;
$search = " Fadjar Nurswanto " ;
$object -> clear_all_assign();
$object -> setFields( $fields );
$object -> setTables( $tables );
$object -> setSearch( $search );
if ( ! $object -> getQuerySQL()){ echo  $object -> Error; exit ;}
else { $sql = $object -> Result; echo  $sql . "
" ;}
echo  " Result Generate List with search on some fields
" ;
$fields = Array ( " id " , " name " , " address " , " city " );
$tables = Array ( " customer " );
$id = 1 ;
$search = Array (
       " name " => " Fadjar Nurswanto " ,
       " address " => " Tomang Raya "
    );
$object -> clear_all_assign();
$object -> setFields( $fields );
$object -> setTables( $tables );
$object -> setSearch( $search );
if ( ! $object -> getQuerySQL()){ echo  $object -> Error; exit ;}
else { $sql = $object -> Result; echo  $sql . "
" ;}
?>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

长春门户网站

长春门户网是网民了解长春的网络窗口,同是提供长春地区百姓生活分类供求信息的门户网站,同时提供长春网站建设、长春网站设计,我们将逐步的完善网站分类信息资源;

长春门户网二维码

联系我们

  • 工作时间:早上8:00 - 晚上5:30
  • 投稿联系:13624467185(微信同号)
  • 反馈邮箱:5053050@QQ.com
  • 公司地址:吉林省长春市亚泰大街与自由大路交汇五环国际大厦1408室

QQ|小黑屋|手机版|Archiver|cc! ( 吉ICP备2021009740号-8 )

Powered by Discuz! X3.4 © 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表