Re: perl with mysql which takes a file as a input that contains the info to create the tables
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Tue, 30 Oct 2007 22:16:28 +0100
On 30 Oct 2007 at 14:11, Klaus Jantzen wrote:
prady wrote:
hi allThat is not correct.
i am creating a perl script which takes the input from the file to
create tables, inserting values into the database. As you all know
the only procedure for taking input from a file (using perl script)
into MySQL database is through (?) place holders.
Right.
for example ,Without the "prepare" you can write:
$sth=$dbh->prepare
("INSERT INTO checkin (firstname, lastname,
destination)
VALUES
(? , ? , ? )");
$rows=0;
open FILE, "passlist.txt" or die $!;
while (<FILE>) {
chomp;
($firstname, $lastname, $destination) = split(/:/);
$sth->execute($firstname, $lastname, $destination)
|| die "Couldn't insert record : $DBI::errstr";
my $sql = qq/ INSERT INTO checkin SET firstname="$firstname",
lastname="$lastname", destination="$destination"/;
my $rc = $dbh->do{$sql};
Sure you can. And I can delete your database then.
Let me see, what happens if I claim my destination is
See you"; DELETE FROM checkin; SELECT "gone
The fact that you can insert the data without the prepare() doesn't
mean you should try to do that. And if you insist, at least use $dbh-
quote() to make sure the values are safe to insert into the query.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- References:
- Prev by Date: Re: Perl 5.8.6 bug in open()?
- Next by Date: Re: Pragmas use strict and use warnings
- Previous by thread: Re: perl with mysql which takes a file as a input that contains the info to create the tables
- Next by thread: Perl 5.8.6 bug in open()?
- Index(es):
Relevant Pages
|