更新删除
<?php
$link = mysqli_connect('localhost', 'root', '', 'test')
or die('Connect Error: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error());
mysqli_set_charset($link, 'UTF8');
$sql = "UPDATE user SET age=age+10 WHERE id=15;";
$sql .= "DDELETE FROM user WHERE id=16";
$res = mysqli_multi_query($link, $sql);
var_dump($res);//boolean true
mysqli_close($link);
?>
预处理语句
<?php
$link = mysqli_connect('localhost', 'root', '', 'test')
or die('Connect Error: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error());
mysqli_set_charset($link, 'UTF8');
$sql = "INSERT user(username,password,age) VALUES(?,?,?);";
$stmt = mysqli_prepare($link, $sql);
$username = "test123";
$password = "test123";
$age = 123;
mysqli_stmt_bind_param($stmt, 'ssi', $username, $password, $age);
$res = mysqli_stmt_execute($stmt);
$username = "test1234";
$password = "test1234";
$age = 44;
mysqli_stmt_bind_param($stmt, 'ssi', $username, $password, $age);
$res = mysqli_stmt_execute($stmt);
var_dump($res);//boolean true
mysqli_close($link);
?>