[ Team LiB ] Previous Section Next Section

Workshop

Quiz

1:

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

2:

Which MySQL function would you use to select a database?

3:

Which function would you use to send a SQL query to a MySQL database?

4:

What does the mysql_insert_id() function do?

5:

How would you declare an auto-increment field for a SQLite database?

6:

Which function would you use to execute a SQL statement with the SQLite functions?

7:

Which object is returned by DB::connect()?

8:

How would you get a unique id for a row using the PEAR::DB package?


Answers

A1:

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

A2:

The mysql_select_db() function attempts to select a database.

A3:

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

A4:

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

A5:

You can define an auto-increment field in a SQLite database by declaring a field as INTEGER PRIMARY KEY in a CREATE statement, like so:

CREATE TABLE thing ( id INTEGER PRIMARY KEY, name VARCHAR(100) );

A6:

The sqlite_query() function executes a SQL statement.

A7:

DB::connect() returns an object of type DB_common. This is always a child implementation specific to a database application.

A8:

The DB_common::nextID() method can be used to get a unique id, as shown here:

$id = $db->nextId('sequencename');


    [ Team LiB ] Previous Section Next Section