Text Delim insert
Moderator: General Moderators
Text Delim insert
Does anyone know of a script that will take a text delimited file of say 1000 + lines and insert it into a mySQL table.
Ah, sorry. But you didn't mention much in your post so I wouldn't know how far you have advanced. =)
Can you give us more info?
Is the file one big 'ol line with stuff? Or are they rather 1000's of lines with words, or sentences, or... ...'garbled' info?
Please copy n' paste a couple of lines in code tags for us to look at, if wanted. Easier to explain with something you can relate to.
Can you give us more info?
Is the file one big 'ol line with stuff? Or are they rather 1000's of lines with words, or sentences, or...
Code: Select all
foo;bar;text;code;1;valuesPlease copy n' paste a couple of lines in code tags for us to look at, if wanted. Easier to explain with something you can relate to.
Last edited by JAM on Tue Jan 06, 2004 6:21 pm, edited 1 time in total.
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
http://www.hotscripts.com and http://www.scriptsearch.com are surely your friends 
Cheers,
Sco.
Edit: URL correction.
Cheers,
Sco.
Edit: URL correction.
Last edited by scorphus on Tue Jan 06, 2004 7:29 pm, edited 1 time in total.
Thanks Jam here is what I have 1000's of links, each link can be a line we can format the lines in the text file. The DB looks like this (hope yous see it all.
for the values the 2 is incremental, 3 is the category, we need NULL, Date Time stamp but as you see my test worked with zeros for the time, and we nee the two 0's.
Does that help?
Code: Select all
INSERT INTO `gl_pllinks` VALUES (2, 'Site Name', 'http://www.xxxx.com', NULL, '2004-01-06 00:00:00', '', 3, '123abc.gif', '', '', '', 'admin@xxxx.com', 0, 0, '', '');Does that help?
Well... still abit confused, as this is the inserting part only, not an example from the actual source... (You arn't moving data from one database to another by any chance?)
But if I didn't misunderstand completely, this example might be interesting?
text.txt :
It might look funny, but it's only to try to explain whats happening... If I missed the point, feel free to tell me/us more.
But if I didn't misunderstand completely, this example might be interesting?
text.txt :
Code: Select all
PHPDN|http://forums.devnetwork.net|foo@devnetwork.net
FOO|http://www.foo.net|foo@foo.orgCode: Select all
// read the file into an array
$array = file("text.txt");
// loop the file, line by line, each time giving $val a new line-data
foreach ($array as $val) {
// create a new array using explode() and the delim's
$data = explode("|",$val);
// example debug, shows what we have now...
print_r($data);
$sql = "INSERT INTO gl_pllinks VALUES
(
'', // an auto_inc field can be left ''. incr. itself
'{$data[0]}', // in this example, Sitename
'{$data[1]}', // in this example, www addy
NULL,
NOW(), // Current date
'',
3,
'123abc.gif',
'',
'',
'',
'{$data[2]}', // in this example, Email addy
0,
0,
'',
'')";
// debugging, should be the actual call to the database here...
echo $sql;
}Example from SAMS Teach Yourself MySQL by Julie C. Meloni
I had to do the same thing. Take info from a text file...that worked. I'm not sure how your text file looks like. Maybe you could post a few lines so we can see what it looks like.LOAD DATA [LOCAL} INFILE 'file_name.txt'
INTO TABLE table_name
FIELDS TERMINATED BY 'somechar'
ECLOSED BY 'somechar'
ESCAPED BY 'somechar'
LINES TERMINATED BY 'somechar';