Hello all,

I'm trying to get a table from a text file with columns delimited by the "|"
sign and I can't do it right.

I've made a perl script that gets the file, parses it, and inserts the
variables into the table, but the problem is that the text contains
characters like " ' ?

I've tried using the $sth -> quote() function but it doesn't quote the
characters like "?".
For each question mark sign (?) found, mysql replaces it with "null".

I also tried using $sth -> execute("insert into table values(?,?,?)");
and $sth -> execute($var1, $var2, $var3); etc, but it gives me only errors.

Could you tell me if the following script is OK?
Note: It uses DBD::mysqlPP and not DBD::mysql, because only this module can
be used under Perl 5.8, but it should work the same.

#!/perl/bin/perl -w

use strict;
use DBI;

my $sth = DBI -> connect("dbi:mysqlPP:database=test;host=localhost",
'teddy', undef, {'RaiseError' => 1});

my $file = "f:/teddy/data/search/index_search.txt";
open (IN, $file);

while (<IN>) {
chomp;
my($url, $time, $titlet, $titlew, $desct, $descw, $keysw, $bodyw) = split
/\|/, $_;
$sth -> do("insert into search values(" . $sth -> quote($url) . "," .
$sth -> quote($time) . "," . $sth -> quote($titlet) . "," . $sth ->
quote($titlew) . "," . $sth -> quote($desct) . "," . $sth -> quote($descw) .
"," . $sth -> quote($keysw) . "," . $sth -> quote($bodyw) . ")");

}


#Thank you.



Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to