IT Community - Software Programming, Web Development and Technical Support

How to connect MySQL from Perl script

This is a discussion on How to connect MySQL from Perl script within the Perl forums, part of the Software Development category; Hi techies, Can someone explain me about the Perl -> Mysql database connection details ?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Perl

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-12-2007, 06:34 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default How to connect MySQL from Perl script

Hi techies,

Can someone explain me about the Perl -> Mysql database connection details ?
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-12-2007, 07:16 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default How to connect MySQL from Perl script

hi..

see this link..

http://blob.perl.org/books/beginning...145_Chap13.pdf
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-12-2007, 10:26 PM
Gopisoft Gopisoft is offline
D-Web Sr.Programmer
 
Join Date: Feb 2007
Posts: 117
Gopisoft is on a distinguished road
Default Re: How to connect MySQL from Perl script

Hi,

Use perl script to access the MySQL Database. See below for a sample perl script that connects to a MySQL database, runs a query, and then disconnects:

#!/usr/bin/perl
print "Content-type: text/html \n\n";
use DBI;

# Connect To Database
$database = "your database name";
$username = "your database username";
$password = "your database password";
$hostname = "mysqlhost";
$db = DBI->connect("DBI:mysql:$database:$hostname", $username, $password);

# Execute a Query
$query = $db->prepare("SELECT * FROM test");
$query->execute;

# How many rows in result?
$numrows = $query->rows;

# Display Results
while (@array = $query->fetchrow_array) {
($field1, $field2, $field3) = @array;
print "field1 = $field1, field2 = $field2, field3 = $field3 ";
}

# Cleaning Up
$query->finish;
$db->disconnect;
exit(0);



NOTE: The mysql password should be no more than 8 alpha-numeric characters. To identify the database username, password and dbid.

-R.Gopi
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002 (HY000): Can't connect to local MySQL server through socket Gopisoft Database Support 1 10-29-2007 03:07 AM
How to connect FTP Server using Perl? raj Perl 1 07-20-2007 03:45 AM
How to set Perl Interpreter within perl script sivaramakrishnan Perl 1 07-19-2007 06:45 AM
problem when connect mysql for php Jeyaseelansarc PHP Programming 1 05-20-2007 10:39 PM
My Favorite Perl Script theseokit Perl 2 03-24-2007 12:20 AM


All times are GMT -7. The time now is 03:08 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0