Workshop
Quiz
How would you open a connection to a MySQL database server?
What function would you use to select a database?
What function would you use to send a SQL query to a database?
What does the mysql_insert_id() function do?
Assuming that you have sent a successful SELECT query to MySQL, name three functions that you might use to access each row returned.
Assuming that you have sent a successful UPDATE query to MySQL, what function might you use to determine how many rows have been updated?
What function would you call if you want to list all databases available from a MySQL server?
What function would you use to list all tables within a database?
Quiz Answers
You can connect to a MySQL daemon using the mysql_connect() function.
The mysql_select_db() function attempts to select a database.
You can send a SQL query to the database server with the mysql_query() function.
mysql_insert_id() returns the value of an automatically incrementing field after a new row has been added to a table.
You can use the mysql_fetch_row(), mysql_fetch_array(), or mysql_fetch_ object() functions to access each row of a found set.
You can discover the number of rows altered by a SQL statement with the mysql_ affected_rows() function.
The mysql_list_dbs() function returns a result pointer that can be used to list all the databases available.
The mysql_list_tables() function returns a result pointer that can be used to list all the tables within a database.
Activities
Create a database with three fields: email (up to 70 characters), message (up to 250 characters), and date (an integer that will contain a UNIX timestamp). Build a script to allow users to populate the database.
Create a script that displays the information from the database you created in activity 1.