Multiple choice general knowledge math & puzzles

What is the correct way of PHP syantax to connect to a MySQL database?

  1. mysql_open("localhost");

  2. mysql_connect("localhost");

  3. dbopen("localhost");

  4. connect_mysql("localhost");

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

mysql_connect() was the historical PHP function for connecting to MySQL databases (though deprecated in PHP 5.5 and removed in PHP 7.0). Modern PHP applications should use mysqli_connect() or PDO instead. The other options (mysql_open, dbopen, connect_mysql) are not standard PHP functions. The correct syntax would typically include username, password, and database name parameters.

AI explanation

In classic (pre-PDO/mysqli) PHP, the function used to open a connection to a MySQL server is mysql_connect(), typically called with the hostname, username, and password. The other listed names — mysql_open, dbopen, connect_mysql — are not real PHP functions. Note that mysql_connect is now deprecated/removed in modern PHP in favor of mysqli_connect or PDO, but it is the historically correct syntax being tested here.