menu

PHP Database Connection

PHP Database Connection - Important Points


1. What is the function used to establish a connection to a MySQL database in PHP?

A. my_sqli_connect()

B. mysql_connect()

C. pdo_connect()

D. mysqli_connect()

Discuss Work Space

Answer: option d

Explanation:

mysqli_connect() function is used to establish a connection to a MySQL database in PHP.

2. Which of the following is the correct syntax to connect to a MySQL database in PHP?

A. $conn = mysqli_connect("localhost", "username", "password", "database_name");

B. $conn = mysql_connect("localhost", "username", "password", "database_name");

C. $conn = pdo_connect("localhost", "username", "password", "database_name");

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

The correct syntax to connect to a MySQL database in PHP using mysqli_connect() function is: $conn = mysqli_connect("localhost", "username", "password", "database_name");

3. Which of the following functions is used to close a database connection in PHP?

A. mysqli_close()

B. mysql_close()

C. pdo_close()

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

mysqli_close() function is used to close a database connection in PHP.

4. Which of the following functions is used to select a database in PHP?

A. my_sqli_select_db()

B. mysql_select_db()

C. pdo_select_db()

D. mysqli_select_db()

Discuss Work Space

Answer: option d

Explanation:

mysqli_select_db() function is used to select a database in PHP.

5. Which of the following functions is used to execute a query in PHP?

A. mysqli_query()

B. mysql_query()

C. pdo_query()

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

mysqli_query() function is used to execute a query in PHP.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now