PHP和数据访问之(插入。删除。和更新数据)

插入:

<?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/>\n";
	$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/>\n";
	$conn->close();
	exit;
}else{
	echo "I modified {$conn->affected_rows} rows.<br/>\n";
}
?>

 可以查询mysqli类的affected_rows属性。 

 

posted @ 2015-01-21 14:50  选择了就坚持  阅读(260)  评论(0编辑  收藏  举报