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.
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...
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().
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.
phpmyadmin?
Originally posted by Tha.Riddla
phpmyadmin?
i have that.
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.
Well i just read my first post and now i see i didn't explain it how i should
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.
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...
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.