使用预处理语句实现插入删除修改数据

预处理插入语句
   
     
  1. $m=new mysqli('localhost','root','','db');
  2. $m->set_charset('utf8');
  3. $stmt=$m->prepare('insert into stu values(null,?,?,?)');
  4. $n='aa';
  5. $g='保密';
  6. $s=10;
  7. $stmt->bind_param('ssi',$n,$g,$s);
  8. $stmt->execute();
  9. $stmt->close();
  10. $m->close();
预处理实现数据删除
   
     
  1. $m=new mysqli('localhost','root','','db');
  2. $m->set_charset('utf8');
  3. $stmt=$m->prepare('delete from stu where sid in (?,?)');
  4. $id1=1;
  5. $id2=2;
  6. $stmt->bind_param('ii',$id1,$id2);
  7. $stmt->execute();
  8. $stmt->free_result();
  9. $stmt->close();
  10. $m->close()
使用预处理语句实现数据的修改
   
     
  1. $m=new mysqli('localhost','root','','db');
  2. $m->set_charset('utf8');
  3. $stmt=$m->prepare('update stu set sname=? where sid=?');
  4. $s='hello';
  5. $d=7;
  6. $stmt->bind_param('ss',$s,$d);
  7. $stmt->execute();
  8. $stmt->free_result();
  9. $stmt->close();
  10. $m->close();






你可能感兴趣的:(删除)