PHP MySQL 更新记录
PHP的mysql_query()函数用于更新表中的记录。自从PHP5.5版本以来,mysql_query()函数已经被弃用。现在建议使用以下两种替代方案之一:
- mysqli_query()
- PDO::__query()
PHP MySQLi 更新记录示例
示例:
<?php
host = 'localhost:3306';user = '';
pass = '';dbname = 'test';
conn = mysqli_connect(host, user,pass,dbname);
if(!conn){
die('Could not connect: '.mysqli_connect_error());
}
echo 'Connected successfully<br/>';
id=2;name="Rahul";
salary=80000;sql = "update emp4 set name=\"name\", salary=salary where id=id";
if(mysqli_query(conn, sql)){ echo "Record updated successfully";
}else{
echo "Could not update record: ". mysqli_error(conn);
}
mysqli_close($conn);
?>
输出:
Connected successfully
Record updated successfully