Chapter 15. Perl Connects with MySQL
By the time you finish this chapter, you should be able to read and write the following Perl code:
use DBI;$dbh = DBI->connect('dbi:mysql:sample_db','root','letmein') or die "Connection Error: $DBI->errstr\n";$sql = "select * from teams";$sth = $dbh->prepare($sql);$sth->execute or die "SQL Error: $sth->errstr\n";while (@row = $sth->fetchrow_array) { print "@row\n";}$sth->finish;$dbh->disconnect;
15.1 Introduction
The user has filled out a form and submitted it with a list of items he wants to purchase. Information for that user is stored in a database in a table called
Get Perl by Example 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.