If you need to develop a website with dynamic content, then you must use a database. Although modern websites are inseparable from databases, many developers still have little understanding of how it works.
PHP supports many types of databases, but PHP certification is only related to PHP capabilities, so the topics in this chapter will not specifically focus on a specific database management system. Additionally, most commercial DBMS, such as MySQL AB, have their own certification courses.
This chapter tests your knowledge of database principles and database programming—independent of a specific DBMS.
Question
1. Consider the following SQL statement. Which option limits the number of records returned? (Double choice)
SELECT * FROM MY_TABLE
A. If possible, use Convert query to stored routine
B. If the program allows it, specify the range of records to be returned to the query
C. If possible, add where condition
D. If the DBMS allows it, convert the query into a view
E. If your DBMS allows it, use prepared statements
2. Can the data set returned by the query be filtered by adding ______ conditions?
Answer: ____________
3. What is inner join used for?
A. Link two tables into one persistent table through the same fields
B. Create a result set based on the same identical rows in two tables
C. Create a dataset based on records in a table
D. Create a result set containing identical records from two tables and all records from one table
E. None of the above is correct
4. Which of the following DBMS does not have PHP extension library?
A. MySQL
B. IBM DB/2
C. PostgreSQL
D. Microsoft SQL Server
E. None of the above is correct
5. Consider the following script. Assume that the mysql_query function sends an unfiltered query statement to an open database connection. Which of the following options is correct? (Double choice)
The following is the code snippet:
$r = mysql_query (DELETE FROM MYTABLE WHERE ID= . $_GET[ID]);
?>
A. There are more than 1 records in the MYTABLE table
B. User-entered data needs to be properly escaped and filtered
C. Calling this function will generate a record that contains the number of other records
D. Passing ID=0+OR+1 to the URL will cause all tables in MYTABLE to be deleted
E. The query statement should contain the database name
6. The ______ statement can be used to add new records to an existing table.
Answer: ____________
7. Which of the following statements is correct?
A. Using indexes can speed up data insertion
B. A good indexing strategy helps prevent cross-site attacks
C. The index should be designed according to the actual application of the database
D. Deleting a record will cause the index of the entire table to be destroyed
E. Only numeric record rows require index
8. Can joins be nested?
A. Can
B. Can't
9. Consider the following data table and query. How to add index to improve query speed?
CREATE TABLE MYTABLE (
ID INT,
NAME VARCHAR (100),
ADDRESS1 VARCHAR (100),
ADDRESS2 VARCHAR (100),
ZIPCODE VARCHAR (10),
CITY VARCHAR (50),
PROVINCE VARCHAR (2)
)
SELECT ID, VARCHAR
FROM MYTABLE
WHERE ID BETWEEN 0 AND 100
ORDER BY NAME, ZIPCODE
A. Add index to ID
B. Add index to NAME and ADDRESS1
C. Add an index to ID, then add indexes to NAME and ZIPCODE
D. Add index to ZIPCODE and NAME
E. Add full text search to ZIPCODE