Page 1 of 1

MySql text table retrieve

Posted: Wed Oct 05, 2005 4:09 am
by AGISB
Here is my problem:

I got a text table that has a text file like this:

----start----
name
workstep
workstep
workstep
.
.
-*--
status
--*--
comment
comment
.
.
---*--
part
part
.
.
---end----

Now I need to split this text file into lines. I got no experience with how MySQl delivers the text file. I expect to get a newline and ch.return

So I thought to first explode each part at the marks (e.g. -*--) and then explode it by the newline char if that is possible but I suspect there might be a more elegant way.

is there a function like fget for strings?

Any ideas?

Posted: Wed Oct 05, 2005 7:30 am
by feyd
maybe you're looking for something like this: viewtopic.php?t=37400 ?

Posted: Wed Oct 05, 2005 8:54 am
by AGISB
According to the manual explode works faster than preg_split. I have the explode version and I was wondering if there was a function that already did what I programmed.

Posted: Wed Oct 05, 2005 9:01 am
by feyd
an SQL file isn't really breakable by lines as tables are often created using multiple lines, insertion queries could take multiple lines, etc. Yes, explode() is faster than preg_split() but preg_split() is 1000 times more flexible as I illustrated in that thread, which seems to have a nearly identical goal. If you simply want to break the file apart into literal lines, then file() does that natively, but if you want the individual commands that would be run, the solution provided in the linked thread would be the starting place to work from most likely.

Posted: Thu Oct 06, 2005 12:08 am
by AGISB
I totally agree that preg_split is way more flexible but in this case those files are created by an application to be saved to the harddisk. As the table structure is very complex and I don't have the source of the application I created a little tool to be run by the client which places that file into a database I got access to. I decided to use that way and not to move the whole file due to security reasons.

Therefore the file is always in the same structure and is placed in the database as whole. So basically I could use preg_split as well as explode as time is not an issue but I find it easier to use explode.