Jump to content

import .sql


Imaulle

Recommended Posts

Hello,

 

I'm having trouble with the following code  :shrug:

 

$file = file_get_contents("database.sql");

$queries = explode(";",$file);

for ($i=0,$c=count($queries);$i<$c;$i++){
mysql_query($queries[$i],$mlink);
}

 

the problem is the sql file I'm trying to import has ; alllll over the place, not just at the end of the queries, so the queries are not getting inputted correctly. I could see a way to fix this if each query was on a single line, but some of them are over 100 lines each.

 

 

How do I make sure it only explodes using the ; at the end of query? and not the ; that are actually in the tables etc.

 

 

 

 

thanks

Link to comment
Share on other sites

all of the .sql files are phpMyAdmin dumps, so I assume all of the queries end with ; and then a line break ?

 

 

this script is for doing a setup of a website, that I gotta install very very many times. I basically upload a zip file, an sql file, and a php file. I then run the php file which will unzip the website, make the sql db, user, add permissions and then a few other things related to the website files.

 

I want to stay out of cPanel, this way is muuuuuuuuch faster

Link to comment
Share on other sites

as far as I can tell this works

 

$file = file_get_contents("database.sql");

$queries = explode(";\n",$file);

for ($i=0,$c=count($queries);$i<$c;$i++){
mysql_query($queries[$i],$mlink);
}

 

 

so I guess I can mark this solved unless someone can see an issue with it D:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.