TwelvestoneBack End

Auto install MySQL database using PHP


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
The General
 
2012-01-12

Anyone know how you can install a SQL (blabla.sql) in a database where the database itself also needs to be created (prefix_randomname + password (which can be fixed)). The user is always the same.

the real me
 
2012-01-12

There are going to be a lot of variables that can affect the answer to that honestly.

The format of the sql file (does it contain CREATE DATABASE or not), how big the files are, the source (are they coming from you or an outside source?) etc...

Stickman
 
2012-01-12

First thing to check is that your host is set up to allow your db user to create databases -- in my experience most shared hosts disable this privilege, and you have to create databases manually via the control panel.

Beyond that, the main problem you're going to have is that PHP's mysql_query() doesn't support running multiple queries. For that you'll need something like mysqli's multi_query().

The General
 
2012-01-13

Thing is that it isn't an existing project yet, just looking into it if it might be possible.

So structure of the SQL can be made how we want and i have a dedicated server so i can change whatever i need to make it work.

Tha.Riddla
 
2012-01-13

phpmyadmin?

The General
 
2012-01-13

Originally posted by Tha.Riddla

phpmyadmin?

i have that.

the real me
 
2012-01-13

If you have phpmyadmin that is by far the easiest approach. You can handle setting the db name and everything else in the sql file itself.

The General
 
2012-01-13

Well i just read my first post and now i see i didn't explain it how i should k That's what you get after typing it on a cellphone at the airport after 24 hours of no sleep.

Thing is this:

  • We have a SQL file, let's call it blabla.sql, it's filled with data and stuff.
  • We need a PHP that can create a database (be it with a random name and always the same password and user)

The idea here is that someone creates an account it creates a new directory with a bunch of files in it and creates a new database (with the info from blabla.sql in it) So the question is how can PHP do this or wouldn't it be possible?

Another approach would be pre-creating databases with the info in it and when someone creates an account it picks an available database.

the real me
 
2012-01-13

I'm sure there are many security holes with this approach but if you are controlling all of the aspects of the process it may be ok if you are just looking for something simple. Once you have your sql file setup properly (including the create database stuff) you could just use php to execute the mysql command line client to load the sql file.

Off the top of my head something like:

$mysqluser = "username"
$pass = "password"
$sqlfile = "/path/to/sql/file"
$result = `mysql -u $mysqluser -p$pass < $sqlfile`
echo $result

I haven't tested that or anything

If you don't want to define the database name in the sql file you can just add a parameter for that

something like:

$mysqluser = "username"
$pass = "password"
$sqlfile = "/path/to/sql/file"
$dbname = "whateveryouwantdbnametobe"
$result = `mysql -u $mysqluser -p$pass $dbname < $sqlfile`
echo $result

This is all pretty hackish though and has no kind of error checking, etc. but it's a start...

The General
 
2012-01-15

Thanks for the info.

After considering all options we probably gonna do it will pre-created databases. Where a user is just assigned to any of those databases.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

Auto install MySQL database using PHP