用UPDATE 语句在数据库表中修改数据。
UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;
UPDATE 数据表名 SET 列名1=值1,列名2=值2,... WHERE 某列=某值;
在test数据库里user表有以下数据:
+------+---------+----------+ | id | Name | password | +------+---------+----------+ | 1 | zhansan | 123 | | 2 | lisi | 345 | | 3 | liming | 456 | +------+---------+----------+
更新user表的password字段为"111"
<?php $link = @mysqli_connect('localhost', 'root', 'root', 'test','3306'); $newpassword='111'; if (!$link) { die('连接失败!'.mysqli_connect_error()); }else{ $sql = "UPDATE user SET password=$newpassword"; $result = mysqli_query($link,$sql); echo "已更新!"; mysqli_close($link); } ?>
+------+---------+----------+ | id | Name | password | +------+---------+----------+ | 1 | zhansan | 111 | | 2 | lisi | 111 | | 3 | liming | 111 | +------+---------+----------+
由于没有写WHERE字句指定条件,则是更新整张表的password为“111” |