MySQL原生代码增删改查

$db = new PDO("mysql:host=localhost;dbname=website_1", 'root', 'root');
	$sql = "SELECT * FROM user";
	$sql = "SELECT * FROM user WHERE id=5";
	$sql = "SELECT * FROM user WHERE id>5";
	$sql = "SELECT * FROM user WHERE name='feige' or pass='xdrvrr'";
	//$sql = "SELECT * FROM user WHERE qq=3432432";
	//$sql = "SELECT * FROM user WHERE phone=13219057177";
	$sth = $db->query($sql);
	while($row = $sth->fetch(PDO::FETCH_ASSOC)){
		echo '
'; print_r($row); echo '
'; } if($sth){ echo "成功查询"; } $sql = "INSERT INTO user ('id','name','pass','qq','phone','create_time','update_time') VALUES('11','hyy','21332','111111','123232','12','13')"; $res = $db->exec($sql); if($res){ echo "成功添加"; } $sql="UPDATE user set pass='123456' WHERE id=4"; $sql="UPDATE user set name='feige',pass='xdrvrr' WHERE id=5"; $sql="UPDATE user set qq='3432432',phone='13219057177' WHERE id=8"; $hyy=$db->exec($sql); if($hyy){ echo "成功更新"; } //$sql="DELETE FROM user WHERE id=8"; //单条删除 $sql="DELETE FROM user WHERE id in(1,2,6,7)"; //多条删除 $hhh=$db->exec($sql); if($hhh){ echo "成功删除"; }

你可能感兴趣的:(php)