This set of PHP Quiz focuses on “Working with Databases-2”.
1. Which one of the following statements should be used to include a file?
a) #include ‘filename’;
b) include ‘filename’;
c) @include ‘filename’;
d) #include <filename>;
Explanation: Include in PHP will takes all the code from the specified file and copies to the existing file containing include statement. An example of this-
//begin database selection and queries.
2. Which one of the following methods is responsible for sending the query to the database?
Explanation: The method mysqli_query() is responsible for sending the query to the database. Query() method was previously used in older versions of PHP.
3. Which one of the following methods recuperates any memory consumed by a result set?
Explanation: The function mysqli_free_result() is used to free the memory which is associated with the result. Once this method is executed, the result set is no longer available. Free() function was used in the previous version of PHP.
4. Which of the methods are used to manage result sets using both associative and indexed arrays?
a) get_array() and get_row()
b) get_array() and get_column()
c) fetch_array() and fetch_row()
d) mysqli_fetch_array() and mysqli_fetch_row()
Explanation: The method mysqli_fetch_array() is used to fetch a result row as an associative array or a numeric array.
And the function mysqli_fetch_row() is used to fetche one row from a result-set and returns it as an enumerated array.
The method fetch_array() and fetch_row() were used in the previous version of PHP.
5. Which one of the following method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE query?
Explanation: The method mysqli_num_rows() is only useful for determining the number of rows retrieved by a SELECT query. But to retrieve the number of rows affected by INSERT, UPDATE, or DELETE query, use mysqli_affected_rows(). Num_rows() and affected_rows() were used in previous version of PHP.
6. Which version of MySQL introduced the prepared statements?
a) MySQL 4.0
b) MySQL 4.1
c) MySQL 4.2
d) MySQL 4.3
Explanation: When the query() method is looped repeatedly it comes at a cost of both overhead, because of the need to repeatedly parsing of the almost identical query for validity, and coding convenience, because of the need to repeatedly reconfigure the query using the new values for each iteration. To help resolve the issues incurred by repeatedly executed queries, MySQL introduced prepared statements.
7. Which of the following methods is used to execute the statement after the parameters have been bound?
Explanation: Once the statement has been prepared, it needs to be executed. Exactly when it’s executed depends upon whether you want to work with bound parameters or bound results. In the case of bound parameters, you’d execute the statement after the parameters have been bound with the bind_param() method.
8. Which one of the following methods is used to recuperating prepared statements resources?
Explanation: The function mysqli_close() is used to close an opened database connection. Once you’ve finished using a prepared statement, the resources it requires can be recuperated with the mysqli_close() method. Close() was used in previous version of PHP.
9. Which method retrieves each row from the prepared statement result and assigns the fields to the bound results?
Explanation: The function mysqli_fetch_row() is used to fetche row from a result-set and returns it as an enumerated array.
Its syntax is mysqli_fetch_row(result);
10. Which method rolls back the present transaction?
Explanation: The function mysqli_rollback() is used to roll back from the current transaction for the specified database connection. Its syntax is: mysqli_rollback(connection);
Rollback() was used in previous version of PHP.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all areas of PHP for Quizzes, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.