Skip to main content

Create database using php code?

Comments

4 comments

  • keat63
    I don't understand your script as I don't really know PHP. Did you manually create the user and password (or is that what the script does)
    0
  • cPanelLauren
    I'd recommend using the UAPI functions in your code for this: Create the DB user UAPI Functions - Mysql::create_user - Developer Documentation - cPanel Documentation Create the DB UAPI Functions - Mysql::create_database - Developer Documentation - cPanel Documentation Set Privileges for a specific user on a specific database:
    0
  • sbutler
    That was the old way with mysqli you have to specify database now. change $conn = new mysqli($servername, $username, $password); TO: $conn = new mysqli($servername, $username, $password, $database);
    0
  • sbutler
    The only way I was able to use that script was to change root MySQL password and try it out on the website outside of WHM/cPanel. Remotely root didn't work but I did get it to work successfully. While I was able to create the database WHM/cPanel was not aware the database existed. Not even when the user name was on the prefixed of the database. The final results there is no way outside of WHM/cPanel to create usable databases. If you are creating a custom installer the user will have too create the database within cPanel first and then run the installer with the new user, password, and database information. That is how all the Admins are doing their installs on cPanel. The API'S for WHM will be discountinued in a future release of WHM/cPanel. I Just don't know the date.
    0

Please sign in to leave a comment.