Executing Simple Queries

Once you have successfully connected to and selected a database, you can start performing queries. These queries can be as basic as inserts, updates, and deletions or as involved as complex joins returning numerous rows. In any case, the PHP function for executing a query is mysql_query():

$result = mysql_query($query);

For simple queries like INSERT, UPDATE, DELETE, etc. (which do not return records), the $result variable will be either TRUE or FALSE depending upon whether the query executed successfully. For complex queries that do return records (SELECT, SHOW, DESCRIBE, and EXPLAIN), the $result variable will be a resource link to the results of the query if it worked or be FALSE if it did not.

One final, albeit optional, ...

Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition 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.