Jump to content


Photo

Create Mysql Databases From Php Script

mysql database create php script

  • Please log in to reply
3 replies to this topic

#1 maicol07

maicol07

    Rank IV Member

  • Members
  • PipPipPipPip
  • 233 posts
  • Gender:Male
  • Location:Italy
  • Interests:Python, Android, Windows, HTML, PHP, JS, WordPress

Posted 08 July 2017 - 12:09 PM

Hi,

it is possible to create MYSQL databases from a PHP script on Tommy?

Thanks


Python, Android and web developer.

Check me out:

My website
My apps website

My GPlay Developer Page

Blog


#2 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 11,041 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 08 July 2017 - 01:25 PM

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.

Please do not PM me for support. Posting on our forums lets all of us learn.
Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#3 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 18,932 posts
  • Gender:Male

Posted 08 July 2017 - 03:30 PM

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.

#4 maicol07

maicol07

    Rank IV Member

  • Members
  • PipPipPipPip
  • 233 posts
  • Gender:Male
  • Location:Italy
  • Interests:Python, Android, Windows, HTML, PHP, JS, WordPress

Posted 08 July 2017 - 04:10 PM

Well, I have found some code on the web... what do you think?

  1. http://www.zubrag.co...ase-creator.php
  2. 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://stackoverflo...ough-php-script

     

  3. <?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.cpane...-cpanel.130825/

Python, Android and web developer.

Check me out:

My website
My apps website

My GPlay Developer Page

Blog






Also tagged with one or more of these keywords: mysql, database, create, php, script

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users