Working with MySQL Data
Inserting, updating, deleting, and retrieving data all revolve around the use of the mysql_query() function to execute the basic SQL queries. For INSERT, UPDATE, and DELETE, no additional scripting is required after the query has been executed because you're not displaying any results (unless you want to). For SELECT, you have a few options for displaying the data retrieved by your query. Let's start with the basics and insert some data, so you'll have something to retrieve later on.
Inserting Data with PHP
The easiest method for inserting data is to simply hard-code the INSERT statement, as shown in Listing 16.6.
Listing 16.6. A Script to Insert a Record
1: <?php 2: // open the connection 3: $conn = mysql_connect("localhost", ... |
Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.