插入:
<?php $conn=@new mysqli('localhost','root','123','mytestdb'); $q_str=<<<EOM insert into users(name,email,date)values('xiaoxue','xue@163.com',now()); EOM; $result=@$conn->query($q_str); if($result===false){ echo "Connect Failed with:$conn->error<br/> "; $conn->close(); exit; }else{ echo "Create new user with id:{$conn->insert_id}"; } ?>
可以查询mysqli类的insert_id属性
更新:
<?php $conn=@new mysqli('localhost','root','123','mytestdb'); $q_str=<<<EOM update users set name='jian' where id=7; EOM; $result=@$conn->query($q_str); if($result===false){ echo "Connect Failed with:$conn->error<br/> "; $conn->close(); exit; }else{ echo "I modified {$conn->affected_rows} rows.<br/> "; } ?>
可以查询mysqli类的affected_rows属性。