For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > a question?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author a question?
cuishang@gmail.com

2007-08-02, 7:00 pm

can you tell me :"using perl, how a file can be stored into mysql
"? that file is a BUG report , which is made from JUNIT .

Chas Owens

2007-08-02, 7:00 pm

On 8/2/07, cuishang@gmail.com <cuishang@gmail.com> wrote:
> can you tell me :"using perl, how a file can be stored into mysql
> "? that file is a BUG report , which is made from JUNIT .


What do you mean by stored? Is the entire file going to be put into
one field, is each line going to go into a separate row, are you going
to parse the file and store relevant information in a hierarchal
manner? Regardless of how you are going to save the data you are most
likely going to need to use the DBI module. The code will look
something like this

#!/usr/bin/perl

use strict;
use warnings;

use DBI;

my $db = "some_database";
my $user = "some_user";
my $pass = "password";
# note: I am not advocating hard coding passwords in scripts,
# this should be read from a config file that has been chmod'ed 400

my $dbh = DBI->connect(
"dbi:mysql:database=foo",
$user,
$pass,
{
ChopBlanks => 1,
RaiseError => 1,
PrintError => 0,
AutoCommit => 1
}
);

my $sth = $dbh->prepare("insert into some_table (some_column) values (?)");

my $data = join '', <>;

$sth->execute($data);

$dbh->disconnect;
usenet@DavidFilmer.com

2007-08-02, 10:00 pm

On Aug 1, 11:00 pm, cuish...@gmail.com wrote:
> can you tell me :"using perl, how a file can be stored into mysql
> "? that file is a BUG report , which is made from JUNIT .


Perl has no built-in limits on the size of the data it can store or
process. You are limited only by the physical constraints of your
hardware (especially memory) and, in your case, the database server
you are using.


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com