小兔网

sql语句中带变量时,数字类型的变量可以不加单引号,但字符串类型的必须加上单引号。

1.插入语句

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

示例2

$sql= "INSERT INTO xt_assets (parent_id,lft,rgt,level,name,title,rules) VALUES ('$parent_id','$lft','$rgt','$level','$name','$title','$rules')";

示例3

$sql = "INSERT INTO xt_assets (parent_id,lft,rgt,level,name,title,rules) VALUES ('{$parent_id}','{$lft}','{$rgt}','{$level}','{$name}','{$title}','{$rules}')";

示例4

当$parent_id是数字类型时,可以省掉单引号

$sql = "INSERT INTO xt_assets (parent_id,lft,rgt,level,name,title,rules) VALUES ($parent_id,'$lft','$rgt','$level','$name','$title','$rules')";
$mysqli->query($sql )

 

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 ";