Lesson 25

Changing Data

In this lesson, you learn how to change the data in your database using the UPDATE command.

There are multiple ways to process MySQL data commands. You have been using variations on similar methods. In this lesson you learn a new way with prepared statements where you set up the statements first and then you supply the field data separately. Prepared statements are inherently safer because they discourage SQL injections.

The examples from this lesson use the same tables used in the examples in Lesson 24.

note

You can download the code for this example from the book's web page at www.wrox.com. You can find them in the Lesson25 folder in the download in a file labeled lesson25a.sql.

The first table is the authors table as shown in Figure 25-1.

The second table is the types table as shown in Figure 25-2.

The third table is the books table as shown in Figure 25-3.

Using the UPDATE Command

The UPDATE command is used to change the data in your tables. To change row 1 in the authors table from Sally Meyers to Sarah Meyers, use ...

Get PHP and MySQL® 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.