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."'");
sql 字符串转数组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 ";
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论