What is the correct way to connect to a MySQL database?
-
dbopen("localhost");
-
mysql_open("localhost");
-
mysql_connect("localhost")
-
connect_mysql("localhost");
Reveal answer
Fill a bubble to check yourself
C
Correct answer
Explanation
The correct way to connect to a MySQL database in PHP uses the mysql_connect() function. Option A's dbopen() doesn't exist, option B's mysql_open() is not a standard PHP function, and option D's connect_mysql() is also not a valid function.
AI explanation
In the classic PHP MySQL extension (mysql_*), the function used to open a connection to a MySQL server is mysql_connect("hostname"). Functions like dbopen, mysql_open, or connect_mysql don't exist in PHP's MySQL API, so mysql_connect is the only valid syntax among the choices.