snowweb
Verified User
Is it possible to create a MySQL database from a PHP script, please?
Kind regards
Peter Snow
http://www.bookkeeper.ph/
Kind regards
Peter Snow
http://www.bookkeeper.ph/
It's so that the website can create databases on the fly from a script each time a customer signs up for our service. I guess I'll just have to stick to creating tables instead.
# read mysql access stuff
DA_MYSQL=/usr/local/directadmin/conf/mysql.conf
DA_USER=`cat $DA_MYSQL | grep user= | cut -d= -f2`
DA_PASS=`cat $DA_MYSQL | grep passwd= | cut -d= -f2`
NEW_DB="${username}_db1"
NEW_USER="${username}@localhost"
# create database
mysql -u $DA_USER -p$DA_PASS --execute="CREATE DATABASE $NEW_DB"
#create user
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"
#create default user
NEW_USER="${username}_usr@localhost"
mysql -u $DA_USER -p$DA_PASS --execute="GRANT ALL on $NEW_DB.* to $NEW_USER identified by '${passwd}'"