Which line of code represents the correct syntax to establish a reference to a database handle?
-
$dbh = DBI::connect("dbi:mysql:myPhoneBook");
-
$dbh = DBD:->connect("dbi::mysql::myPhoneBook");
-
$dbh = DBD::connect("mysql:dbi:myPhoneBook");
-
$dbh = DBI->connect("dbi:mysql:myPhoneBook");
D
Correct answer
Explanation
The correct Perl DBI syntax is DBI->connect() with the DSN string 'dbi:mysql:myPhoneBook'. Options A and B incorrectly use static (::) instead of arrow (->) syntax. Option C has the wrong DSN format (mysql:dbi instead of dbi:mysql). The DBI module uses object-oriented syntax with the arrow operator.