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 ?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| |
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |