PHP Multiple Choice Questions – Database

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

Answer: d
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

Answer: c
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

Answer: a
Explanation: Also make sure that extension_dir directive points to the appropriate directory.
advertisement
advertisement

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

Answer: d
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

Answer: a
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)
);
Note: Join free Sanfoundry classes at Telegram or Youtube

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

Answer: b
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

Answer: d
Explanation: $mysqli->select_db(‘databasename’); can be used to select the database.
advertisement

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

Answer: c
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

Answer: a
Explanation: Error numbers are often used in lieu of natural-language message to ease software internationalization efforts and allow for customization of error messages.
advertisement

10. If there is no error, then what will the error() method return?
a) TRUE
b) FALSE
c) Empty String
d) 0
View Answer

Answer: c
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 questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.