Name
connect( )
Synopsis
DBI->connect(DBI:server:database[:host:port],username,password[, \%attributes])
Use this to establish a connection to MySQL
and to select a database. The first argument includes a list of
settings separated by colons. The name of the module
(DBI), the type of server
(mysql), and the name of the database to use are
required. The hostname or IP address and port number are optional.
The second argument is the username and the third is the
user's password. You can substitute any of these
settings or values with variables—just be sure to enclose each
argument containing variables with double quotes so that the values
will be interpolated. Finally, attributes may be given in the fourth
argument.
my $dbh = DBI->connect('DBI:mysql:bookstore:localhost',
'jacinta','richardson',
{AutoCommit=>0});In this excerpt, Perl is connecting
to the MySQL server with the username of jacinta
and the password of richardson, with the
database bookstore. The attribute of
AutoCommit is set to off so that changes to the
data may be undone using rollback( ). See the end
of this chapter for a list of attributes.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access