php开发中sql语句拼接示例(插入、查询、更新)

1.插入语句

$sql="insert into Ad(AdClassID,AdType,AdTit,AdFileName,AdUrl,AShow,Addtime) values('".$AdClassID."','".$AdType."','".$AdTit."','".$AdFileName."','".$AdUrl."','1','".$Addtime."')";

 2.从数据库中选出数据

$sql = "select * from AdClass order by ID desc";<br><br>$sql="select * from admin where AdminID='".$_SESSION['AdminID']."'";
$fids = str_replace("|",",",$_POST['fileid2']);//$_POST['fileid2'] == "2246|2247|2248"
                    $sql2 = "select save_name from xxf_witkey_file where file_id in(".$fids.")";
                    $b = db_factory::query($sql2);//save_name二维集合数组

3,批量删除

// 1,根据checkbox过来的一维数组, 转成字符串;2、因为是order_id,所有在in 里面使用整型
is_array ( $ckb ) and $ids = implode ( ',',  $ckb );
$order_status = 'close';

$res = db_factory::execute("delete from xxf_witkey_home_order where order_id in (".$ids.") and order_status = '".$order_status."'");

4.更新数据库中记录数据

$sql="update Ad set AdClassID='".$AdClassID."',AdType='".$AdType."',AdTit='".$AdTit."',AdFileName='".$AdFileName."',AdUrl='".$AdUrl."',Addtime='".$Addtime."' where ID=".$ID."";
$SQl = "update xxf_witkey_activity set subhead='".$subhead."' where a_id=".$a_id.""; 

5、进行模糊like查询:

$sql = "select * from xxf_witkey_article where cat_type ='article'  and is_recommend =1 and art_title like '%".$key_word."%' order by art_id desc ";
                
原文地址:https://www.cnblogs.com/xuzhengzong/p/7025957.html