Gossamer Forum
Home : General : Perl Programming :

Changing From Flat File to MYSQL

(Page 2 of 2)
> >
Quote Reply
Re: [Wil] Changing From Flat File to MYSQL In reply to
Except you fail to do any error checking either so you are not going to find the problem.



Quote Reply
Re: [nolimit] Changing From Flat File to MYSQL In reply to
Try this Jeremy:

Code:
#!/usr/bin/perl

use CGI qw(:standard);
print "Content-type: text/html\n\n";
require "shopconfig.cgi";

use DBI;
my $dbh = DBI->connect("DBI:mysql:crashint_test:localhost","crashint", "PASSWORD") or &error($DBI::errstr);
my @count = ();
opendir (DR,"$datapath/members/") or &error($!);
@count = grep { /\.txt$/ } readdir(DR);
closedir (DR);

foreach $line (@count) {
print "$line<br>";
open(LIST, "<$datapath/members/$line") or &error($!);
while(<LIST>) {
@data = split /\|/;
my $sth = $dbh->prepare("INSERT INTO foo VALUES ('$data[0]','$data[1]' ...etc)") or &error($DBI::errstr);
$sth->execute;
$sth->finish;
}
}
$dbh->disconnect();

sub error {
print shift;
exit;
}

Last edited by:

PaulW: Nov 19, 2001, 5:19 AM
Quote Reply
Re: [PaulW] Changing From Flat File to MYSQL In reply to
> opendir (DR,"$datapath/members/") or &error($!);

Should the path to the directory have a trailing slash??

- wil
Quote Reply
Re: [PaulW] Changing From Flat File to MYSQL In reply to
I did use error checking but nothing showed.
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central

Last edited by:

nolimit: Nov 19, 2001, 12:24 PM
Quote Reply
Re: [nolimit] Changing From Flat File to MYSQL In reply to
I think you said you already tried only printing to the screen, but try it again...
Code:
opendir (DB, "C:/data") or die $!;
while (my $file = readdir(DB)) {
next unless $file =~ /\.txt$/;
open (FILE, "C:/data/$file") or die "can't open $file! $!";
print "$file\n" . ("*" x 20) . "\n", <FILE>;
close (FILE);
print "\n\n";
}
closedir (DB);

I'm thinking that if there is no problem printing to the screen, then there is definately a problem with your SQL somewhere.

--Philip
Links 2.0 moderator

Last edited by:

ThatPerson1024: Nov 19, 2001, 2:05 PM
Quote Reply
Re: [ThatPerson1024] Changing From Flat File to MYSQL In reply to
Thanks everyone. After I got time to test, I have got it to work with all your help..
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
> >