Unable to Create New Database using php

I am trying to create a database using PHP. My code is working well in localhost. But in Infinityfree it does not create the database. My code is

$dbname='******_mydb';
$connection=mysqli_connect($dbhost,$dbuser,$dbpass);
$sql="CREATE DATABASE ".$dbname;
mysqli_query($connection,$sql);

I am using $dbhost,$dbuser and $dbpass as provided in “MySQL Details for ****” in Infinityfree

You have to create databases through cPanel, then you can access them through php.

4 Likes

Okay. so is it not possible here to create a database using PHP?
I don’t want to give my username and password to others who are working with me on this project. So I want that they can create a database through PHP code.

That’s correct.

Then how are they working with you on the project? Remember that for each Hosting Account, there is one username and password, which extends to the databases on that Account too.

6 Likes

FYI: Premium hosting has more extensive database permission controls. On premium hosting, your main account user can create databases directly, and you can create additional users with limited permissions (e.g. access to only one database or read only access).

4 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.