Q
Which of the following statements is true regarding database connections in PHP applications?

Answer & Solution

Answer: Option A
Solution:
In PHP applications, database connections should be properly closed after use to release server resources and prevent connection leaks. Failure to close connections can lead to resource exhaustion and degrade application performance.
Related Questions on Average

What is the primary advantage of using PDO over MySQLi for database access in PHP?

A). Portability across different databases

B). Better performance

C). Easier syntax

D). More features

What is the purpose of the PDO::lastInsertId() method in PDO extension?

A). Retrieving the ID generated by the last INSERT statement

B). Executing an SQL query

C). Fetching data from the database

D). Closing the database connection

Which of the following statements is true regarding parameterized queries in MySQLi and PDO?

A). They prevent SQL injection attacks

B). They improve database performance

C). They can only be used with SELECT queries

D). They require additional server resources

What is the primary purpose of database connection pooling in PHP applications?

A). Improving scalability and performance

B). Enhancing database security

C). Simplifying database configuration

D). Reducing server resource usage

Which of the following functions is used to prepare an SQL statement for execution with parameters in MySQLi extension?

A). mysqli_query()

B). mysqli_prepare()

C). mysqli_fetch_array()

D). mysqli_close()

Which of the following is NOT a step in connecting to a MySQL database using PDO extension?

A). Create a PDO object

B). Set database credentials

C). Execute an SQL query

D). Handle connection errors

What is the purpose of the PDO::query() method in PDO extension?

A). Establishing a connection to a database

B). Executing an SQL statement

C). Fetching data from the database

D). Closing the database connection

What is the purpose of the PDO::setAttribute() method in PDO extension?

A). Setting attributes for the PDO connection

B). Executing SQL queries

C). Fetching data from the database

D). Closing the database connection

Which PHP extension provides an improved interface for interacting with MySQL databases?

A). MySQL

B). PDO

C). SQLI

D). MySQLi

What is the primary advantage of using prepared statements in MySQLi and PDO?

A). Improved security and protection against SQL injection

B). Faster execution of SQL queries

C). Simpler syntax for SQL statements

D). Compatibility with older PHP versions