Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

PHP and MySQL MCQs

1. Which PHP function is used to establish a connection with a MySQL server?

a) mysqli_query()
b) mysql_connect()
c) pdo_connect()
d) mysqli_connect()

Answer: d) mysqli_connect()

Explanation: mysqli_connect() is the correct function to establish a connection with a MySQL server using PHP. It establishes a connection and returns a MySQL link identifier.


2. How do you create a new database using PHP and MySQL?

a) mysql_create_db()
b) mysqli_create_database()
c) CREATE DATABASE statement
d) php_create_database()

Answer: c) CREATE DATABASE statement

Explanation: The CREATE DATABASE statement is used in MySQL to create a new database. You can execute this statement using PHP’s mysqli_query() function to create a database through PHP code.


3. Which PHP function is used to select a specific database to work with?

a) mysql_select_db()
b) mysqli_select_database()
c) select_db()
d) mysqli_query()

Answer: b) mysqli_select_database()

Explanation: mysqli_select_database() is used to select a specific database among multiple databases when working with MySQL and PHP.


4. How can you list all databases available on the MySQL server using PHP?

a) mysql_list_databases()
b) mysqli_list_databases()
c) SHOW DATABASES statement
d) list_databases()

Answer: c) SHOW DATABASES statement

Explanation: The SHOW DATABASES statement in MySQL is used to list all databases on the server. You can execute this statement using mysqli_query() in PHP.


5. Which PHP function is used to list all table names in a database?

a) mysqli_list_tables()
b) mysql_list_tables()
c) SHOW TABLES statement
d) list_tables()

Answer: c) SHOW TABLES statement

Explanation: The SHOW TABLES statement in MySQL is used to list all tables in a database. You can execute this statement using mysqli_query() in PHP.


6. How do you create a new table in a MySQL database using PHP?

a) mysql_create_table()
b) mysqli_create_table()
c) CREATE TABLE statement
d) php_create_table()

Answer: c) CREATE TABLE statement

Explanation: The CREATE TABLE statement in MySQL is used to create a new table. You can execute this statement using mysqli_query() in PHP.


7. Which PHP function is used to insert data into a MySQL table?

a) mysql_insert()
b) mysqli_insert()
c) INSERT INTO statement
d) php_insert()

Answer: c) INSERT INTO statement

Explanation: The INSERT INTO statement in MySQL is used to insert data into a table. You can execute this statement using mysqli_query() in PHP.


8. How can you delete a database using PHP and MySQL?

a) mysql_drop_database()
b) mysqli_drop_database()
c) DROP DATABASE statement
d) delete_database()

Answer: c) DROP DATABASE statement

Explanation: The DROP DATABASE statement in MySQL is used to delete a database. You can execute this statement using mysqli_query() in PHP.


9. Which PHP function is used to delete data from a MySQL table?

a) mysql_delete()
b) mysqli_delete()
c) DELETE FROM statement
d) php_delete()

Answer: c) DELETE FROM statement

Explanation: The DELETE FROM statement in MySQL is used to delete data from a table. You can execute this statement using mysqli_query() in PHP.


10. What tool can be used for database administration, including managing databases, tables, and executing queries visually?

a) MySQL Workbench
b) MySQL Command Line Interface
c) PHPMyAdmin
d) SQLyog

Answer: c) PHPMyAdmin

Explanation: PHPMyAdmin is a popular tool for database administration, providing a web interface for managing MySQL databases, tables, and executing SQL queries visually. It is commonly used in conjunction with PHP development.

Leave a Comment