Multiple choice technology web technology

Which is the correct syntax for connecting the mysql database in php?

  1. mysql con=new mysql("Connection string")

  2. mysql("database name");

  3. mysql_connect("database name")

  4. mysql_connect("database",username,password)

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

The correct syntax is mysql_connect() with three parameters: server hostname, username, and password. Option D shows the correct parameter order, though the database name is actually a fourth optional parameter. Options A and B use incorrect syntax, while option C is missing the required connection parameters.

AI explanation

Connecting to MySQL from PHP is done with the procedural mysql_connect() function, which takes the server/database identifier, username, and password as arguments, unlike an object-construction syntax (new mysql(...)) which doesn't exist in PHP's mysql extension. The other options are missing required credentials or use invalid syntax entirely.