
crashinto
Novice
Nov 17, 2001, 11:45 AM
Post #1 of 1
(247 views)
|
|
transfering text files to mysql...
|
Can't Post
|
|
I am writing a little script to change my flat file databases to mysql, I have a seperate file for each member so I needed it to get all files in the folder and open each one individually and then print, but it seems not to work right now. I have right now:
#!/usr/bin/perl use CGI qw(:standard); print "Content-type: text/html\n\n"; require "shopconfig.cgi"; my @count = (); opendir (DR,"$datapath/members/"); @count = grep { /\..*/ } readdir(DR); closedir (DR); foreach $line (sort @count) { open(LIST, "<$datapath/members/$line"); while(<LIST>) { my ($Username, $Password, $lname, $fname, $country, $email, $add1, $add2, $city, $state, $zip, $phone) = split/\|/; use DBI(); # Connect to the database. my $dbh = DBI->connect("DBI:mysql:database=crashint_test;host=localhost", "crashint", "PASSWORD", {'RaiseError' => 1}); # Same thing, but using placeholders $dbh->do("INSERT INTO foo VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef, "$Username", "$Password", "$fname", "$lname", "$country", "$email", "$add1", "$add2", "$city", "$state", "$zip", "$phone"); # Disconnect from the database. $dbh->disconnect(); } close(LIST); } I have printed $line seperately and the files are shown perfectly. I can get it to work if I do each file seperately, but I need them all done at once.
(This post was edited by crashinto on Nov 17, 2001, 10:47 AM)
|