Which is the correct syntax for connecting the mysql database in php?
-
mysql con=new mysql("Connection string")
-
mysql("database name");
-
mysql_connect("database name")
-
mysql_connect("database",username,password)
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.
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.