WebServer.com.my

Portal Home > Knowledgebase > Scripting, Component & Database > Perl > How to connect MySQL using Perl?


How to connect MySQL using Perl?




Portable DBI Methods:
connect($data_source, $username, $password)

Use the connect method to make a database connection to the data source. The $data_source value should begin with DBI:driver_name:.

Example uses of connect with the DBD::mysql driver:
$dbh = DBI->connect("DBI:mysql:$database", $user, $password);
$dbh = DBI->connect("DBI:mysql:$database:$hostname",
$user, $password);
$dbh = DBI->connect("DBI:mysql:$database:$hostname:$port",
$user, $password);



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read