Hi everyone,
I was wondering whether it is possible to create a new database and user, from PHP, on an WHM/cPanel server.
Thanks in advance for your answers,
Constantin TOVISI
Hi everyone,
I was wondering whether it is possible to create a new database and user, from PHP, on an WHM/cPanel server.
Thanks in advance for your answers,
Constantin TOVISI
To create a DB:
mysql_query('create database foo');
or
mysql_create_db('foo');
http://www.php.net/manual/en/function.mysql-create-db.php
To create a MySQL user:
You can create user account by generating the SQL and running it through mysql_query
(just like the first example): http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
As long as the user you use to connect to the database has the appropriate privileges defined in MySQL this shouldn't be a problem.
To create databases the user needs the CREATE privilege (to drop them that would be DROP privilege), to create user(s) you need to have the CREATE USER privilege. You also might need the GRANT OPTION privilege to be able to grant privileges to other users.
So as long as the DB user(s) you can create through WHM/cPanel have these privileges, you should be ok.
Ok, this is the thing.
'mysql_create_db' function does not work properly on cPanel servers.
There is a solution to this though, by using the proprietary cPanel funtion like so
http://USER:PASS@HOST:2082/frontend/SKIN/sql/adddb.html?db=DB
There is also a ready-made script that can be used here http://www.zubrag.com/scripts/cpanel-database-creator.php
Hope people looking for an answer to this question will find this useful,
Constantin TOVISI