Jump to content

How can I load a mysqldump with PHP?


smithaa02

Recommended Posts

Basically, I have a mysql dump with table creates and data inserts all in a giant text file.  What I want to do is to put all those tables into a specified database using PHP.  My questions is what is the best way to this?  mysql_query() can only do one command at a time.
Link to comment
https://forums.phpfreaks.com/topic/31592-how-can-i-load-a-mysqldump-with-php/
Share on other sites

Well, depending on how large the dump file is, there are a couple different options. First, if it's not a huge file, you may be able to run a simple explode() on the semicolons that separate the queries and run each one individually. The only problem here is that if the tables contain text that may have semicolons within it, you may be in for some difficulty. If this is the case, or if the file is large (several MB), you will need to come up with some sort of regular expression match that will grab one query at a time. once you have that in place, you can simply read progressively through the file and run each query as it is completed

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.