Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-03-2009, 12:36 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
Wink Perl Mysql Database connection

How do i connect mysql database using perl. Will like to see sample codes so i can quickly try it out. Thanks

Last edited by big; 07-03-2009 at 12:39 AM. Reason: i want to include an LQ Tag
Old 07-03-2009, 01:41 AM   #2
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Originally Posted by big View Post
How do i connect mysql database using perl. Will like to see sample codes so i can quickly try it out. Thanks
use DBI;
$dsn = "DBI:mysql:database=$database;host=$host;port=$port" or die "Connection Error: $DBI::errstr\n";
$dbh = DBI->connect($dsn, $user, $password);
$sql = "show tables";
$sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";

hope this helps........


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i copt the MYSQL Database to a other server (Database) halvorls Linux - Server 3 07-27-2008 10:19 PM
[mysql/perl] Connection Timeout? incidenta5 Programming 2 05-15-2008 06:08 AM
using perl to insert special characters into mysql database ihopeto Programming 5 12-25-2006 05:08 PM
Perl MySQL Connection abdul_zu Programming 3 06-18-2006 03:06 AM
How to interact with MYSQL database from within perl program Bassam Programming 5 02-26-2004 06:00 PM

All times are GMT -5. The time now is 12:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration