MySql text table retrieve

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

MySql text table retrieve

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe you're looking for something like this: viewtopic.php?t=37400 ?
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post 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.
Post Reply