maicol07 Posted July 8, 2017 Posted July 8, 2017 Hi,it is possible to create MYSQL databases from a PHP script on Tommy?Thanks
wolstech Posted July 8, 2017 Posted July 8, 2017 No. You have to use cpanel to create them. I really wish there was a way to do this, since I would have a use for this functionality as well.
Krydos Posted July 8, 2017 Posted July 8, 2017 Well, technically it's possible. Anything is possible right? You would have to curl in to cpanel, and get a session token, and then use that session token to automate going to the mysql page and submitting a new database. It would be pretty complicated to do.
maicol07 Posted July 8, 2017 Author Posted July 8, 2017 Well, I have found some code on the web... what do you think?http://www.zubrag.com/scripts/cpanel-database-creator.php require("xmlapi.php"); // this can be downlaoded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php $xmlapi = new xmlapi("your cpanel domain"); $xmlapi->set_port( 2083 ); $xmlapi->password_auth($opts['user'],$opts['pass']); $xmlapi->set_debug(0);//output actions in the error log 1 for true and 0 false $cpaneluser=$opts['user']; $databasename="something"; $databaseuser="else"; $databasepass=$opts['pass']; //create database $createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename)); //create user $usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass)); //add user $addusr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduserdb", array("".$cpaneluser."_".$databasename."", "".$cpaneluser."_".$databaseuser."", 'all')); Source: https://stackoverflow.com/questions/11989920/create-cpanel-database-through-php-script <?php include("xmlapi.php"); $db_host = "localhost"; $cpuser = "myuser"; $databasename = 'mydatabasename';//do not prepend with username $databaseuser = 'mydatabaseuser';//api will do that for you $databasepass = '123456'; $xmlapi = new xmlapi($db_host); $xmlapi->password_auth("root","root_pass"); $xmlapi->set_debug(1);//this setting will put output into the error log in the directory that you are calling script from $xmlapi->set_output('array');//set this for browser output //create database $createdb = $xmlapi->api1_query($cpuser, "Mysql", "adddb", array($databasename)); foreach($createdb as $v) { $result = $v['result']; } if ($result == 1) { //create user $usr = $xmlapi->api1_query($cpuser, "Mysql", "adduser", array($databaseuser, $databasepass)); } foreach($usr as $v) { $result2 = $v['result']; } if ($result2 == 1) { //add user to database $addusr = $xmlapi->api1_query($cpuser, "Mysql", "adduserdb", array($databasename, $databaseuser, 'all')); } print_r($addusr); ?> Source: https://forums.cpanel.net/threads/create-database-without-login-to-cpanel.130825/
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now