This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Database”.
1. Which one of the following databases has PHP supported almost since the beginning?
a) Oracle Database
b) SQL
c) SQL+
d) MySQL
View Answer
Explanation: We can connect, insert, update, delete and retrieve data from the databases with the help of PHP and MySQL is the most popular database system used with PHP.
2. The updated MySQL extension released with PHP 5 is typically referred to as _______________
a) MySQL
b) mysql
c) mysqli
d) mysqly
View Answer
Explanation: The updated MySQL extension with PHP 5 is known as MySQL and typically referred to as mysqli.
3. Which one of the following lines need to be uncommented or added in the php.ini file so as to enable mysqli extension?
a) extension=php_mysqli.dll
b) extension=mysql.dll
c) extension=php_mysqli.dl
d) extension=mysqli.dl
View Answer
Explanation: Also make sure that extension_dir directive points to the appropriate directory.
4. In which version of PHP was MySQL Native Driver(also known as mysqlnd) introduced?
a) PHP 5.0
b) PHP 5.1
c) PHP 5.2
d) PHP 5.3
View Answer
Explanation: PHP required that MySQL client library be installed on the server from which PHP was communicating with MySQL, whether the MySQL server also happened to reside locally or elsewhere. PHP 5.3 removes this problem by introducing MySQL Native Driver.
5. Which one of the following statements is used to create a table?
a) CREATE TABLE table_name (column_name column_type);
b) CREATE table_name (column_type column_name);
c) CREATE table_name (column_name column_type);
d) CREATE TABLE table_name (column_type column_name);
View Answer
Explanation: The example creates a table called “student” that contains five columns: SID, LastName, FirstName, Address, and City:
CREATE TABLE student (
SID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
6. Which one of the following statements instantiates the mysqli class?
a) mysqli = new mysqli()
b) $mysqli = new mysqli()
c) $mysqli->new.mysqli()
d) mysqli->new.mysqli()
View Answer
Explanation: If you choose to interact with MySQL server using the object-oriented interface, you need to first instantiate the mysqli class via its constructor.
7.Which one of the following statements can be used to select the database?
a) $mysqli=select_db('databasename');
b) mysqli=select_db('databasename');
c) mysqli->select_db('databasename');
d) $mysqli->select_db('databasename');
View Answer
Explanation: $mysqli->select_db(‘databasename’); can be used to select the database.
8. Which one of the following methods can be used to diagnose and display information about a MySQL connection error?
a) connect_errno()
b) connect_error()
c) mysqli_connect_errno()
d) mysqli_connect_error()
View Answer
Explanation: The mysqli extension includes a few features that can be used to capture error messages or alternatively you can use exceptions.
9. Which method returns the error code generated from the execution of the last MySQL function?
a) errno()
b) errnumber()
c) errorno()
d) errornumber()
View Answer
Explanation: Error numbers are often used in lieu of natural-language message to ease software internationalization efforts and allow for customization of error messages.
10. If there is no error, then what will the error() method return?
a) TRUE
b) FALSE
c) Empty String
d) 0
View Answer
Explanation: The function error is used to deal with error handling and logging. If there is no error, then the error() method will return an empty string.
More MCQs on PHP Database:
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all areas of PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Practice Programming MCQs
- Apply for Programming Internship
- Check PHP Books
- Check Information Technology Books
- Check MCA Books