Home > Articles > Programming > PHP

  • Print
  • + Share This
This chapter is from the book

Workshop

Quiz

  1. How would you open a connection to a MySQL database server?

  2. What function would you use to select a database?

  3. What function would you use to send a SQL query to a database?

  4. What does the mysql_insert_id() function do?

  5. Assuming that you have sent a successful SELECT query to MySQL, name three functions that you might use to access each row returned.

  6. Assuming that you have sent a successful UPDATE query to MySQL, what function might you use to determine how many rows have been updated?

  7. What function would you call if you want to list all databases available from a MySQL server?

  8. What function would you use to list all tables within a database?

Quiz Answers

  1. You can connect to a MySQL daemon using the mysql_connect() function.

  2. The mysql_select_db() function attempts to select a database.

  3. You can send a SQL query to the database server with the mysql_query() function.

  4. mysql_insert_id() returns the value of an automatically incrementing field after a new row has been added to a table.

  5. You can use the mysql_fetch_row(), mysql_fetch_array(), or mysql_fetch_ object() functions to access each row of a found set.

  6. You can discover the number of rows altered by a SQL statement with the mysql_ affected_rows() function.

  7. The mysql_list_dbs() function returns a result pointer that can be used to list all the databases available.

  8. The mysql_list_tables() function returns a result pointer that can be used to list all the tables within a database.

Activities

  1. 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.

  2. Create a script that displays the information from the database you created in activity 1.

  • + Share This
  • 🔖 Save To Your Account