Workshop

The quiz and exercises are provided to help you solidify your understanding of the material covered today. Try to understand the quiz and exercise answers before continuing to tomorrow's lesson.

Quiz

1:What's wrong with the following code?
my $dsn = "DBI:mysql:mydb";
my $db_user = "some_user";
my $db_pass = "some_pass";
my $dbh = $dbh->connect ($dsn, $db_user, $db_pass)
or die "Couldn't connect to MySQL.\n";
A1: The connect() method should reference DBI, not the database handle $dbh. The connect() line should read:
my $dbh = DBI->connect ($dsn, $db_user, $db_pass)
or die "Couldn't connect to MySQL.\n";
2:If you have the following lines to perform a prepare():
 $sth = $dbh->prepare ($sql) or die "Couldn't prepare statement $sql.\n"; ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.