On 8/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to