PHP mysql_query()函数用于更新表中数据记录
由于PHP5.5版本起,不推荐使用mysql_query()函数,建议使用以下2种方法代替
mysqli_query()
POD::_query()
示例
<?php
$host = 'localhost:3306';
$user = 'root';
$pass = '';
$dbname = 'mydb';
$conn = mysqli_connect($root, $user, $pass, $dbname);
if(!$conn)
{
die('Could not connect : '.mysqli_error());
}
echo 'Connected successfully<br/>';
$id = 1;
$name = "ruk";
$emp_salary = 666;
$sql = "update emp5 set name = '".$name."', emp_salary = '".$emp_salary. "'where id = '"."$id"."'";
if(mysqli_query($conn,$sql))
{
echo 'Record updated successfully';
}else{
echo 'Cloud not update record: '.mysqli_error();
}
mysqli_close($conn);
?>
执行上述代码,结果如下
Connected successfully
Record updated successfully
mysql sql语句 update 加法运算
UPDATE table SET column = column+ num;
UPDATE `produce` SET `Qty` = `Qty`+ '6' WHERE `produce`.`Item` = 'SKU';