LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 07-02-2009, 11:36 PM   #1
big
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-02-2009 at 11:39 PM. Reason: i want to include an LQ Tag
 
Old 07-03-2009, 12:41 AM   #2
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Quote:
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;
$database='nameofdatabase';
$host='localhost';
$port='3306';
$user='root';
$password="";
$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........
 
  


Reply


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 09:19 PM
[mysql/perl] Connection Timeout? incidenta5 Programming 2 05-15-2008 05:08 AM
using perl to insert special characters into mysql database ihopeto Programming 5 12-25-2006 04:08 PM
Perl MySQL Connection abdul_zu Programming 3 06-18-2006 02:06 AM
How to interact with MYSQL database from within perl program Bassam Programming 5 02-26-2004 05:00 PM


All times are GMT -5. The time now is 11:55 AM.

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