Home > Database > Mysql Tutorial > body text

mysql如何更新数据库字段教程

WBOY
Release: 2016-06-07 16:20:58
Original
1422 people have browsed it

mysql如何更新数据库字段教程 语法 UPDATE table_name SET column_name = new_value WHERE column_name = some_value 注释:SQL 对大小写不敏感。UPDATE 与 update 等效。 为了让 PHP 执行上面的语句,我们必须使用 mysql_query( 函数。该函数用于向 SQL 连

   mysql如何更新数据库字段教程

  语法

  UPDATE table_name SET column_name = new_value WHERE column_name = some_value

  注释:SQL 对大小写不敏感。UPDATE 与 update 等效。

  为了让 PHP 执行上面的语句,我们必须使用 mysql_query( 函数。该函数用于向 SQL 连接发送查询和命令。

  例子

  稍早时,,我们在本教程中创建了一个名为 "Person" 的表。它看起来类似这样:

  FirstName LastName Age Peter Griffin 35 Glenn Quagmire 33

  下面的例子更新 "Person" 表的一些数据:

  $con = mysql_connect("localhost","peter","abc123");

  if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

  mysql_select_db("my_db", $con);

  mysql_query("UPDATE Person SET Age = '36'

  WHERE FirstName = 'Peter' AND LastName = 'Griffin'");

  mysql_close($con);

  ?>

  在这次更新后,"Person" 表格是这样的:

  FirstName LastName Age

  Peter Griffin 36

  Glenn Quagmire 33

        :更多精彩文章请关注三联编程教程栏目。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template