cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution
Highlighted

creating a new mySQL database from PHP

Hi,

 

I am trying to create a database via PHP as per w3schools, but I seem not to be able to create a user with permissions to do so, am getting connected ok, but then don't have permissions to create a DB due to permissions.

 

Connected successfully to the server.

Create a database

ERROR: Unable to execute CREATE DATABASE storeAccess denied for user 'theUser'@'localhost' to database 'store'

 

the script I am using:

<?php
//mysqli_connect(host, username, password, dbname)
$link = @mysqli_connect("localhost", "theUser", "secretPassword") or die("ERROR: Unable to connect: " . mysqli_connect_error());
var_dump($link);


echo "<p>Connected successfully to the server.</p>";
?>
            <h3>Create a database</h3>
<?php
$sql = "CREATE DATABASE store";
if(mysqli_query($link, $sql)){
    echo "<p>Database store was created successfully</p>";   
}else{
    echo "ERROR: Unable to execute $sql" . mysqli_error($link);   
}

?>

 

anyone would know if there is something wrong with the syntax or where I could create powerfull enough account to be able to create the mySQL DB?

 

thank you

Dusan

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Employee
Employee
Solution

Re: creating a new mySQL database from PHP

Databases cannot be created from PHP with shared hosting. They must already exist or be created from the hosting control panel.

View solution in original post

1 REPLY 1
Highlighted
Employee
Employee
Solution

Re: creating a new mySQL database from PHP

Databases cannot be created from PHP with shared hosting. They must already exist or be created from the hosting control panel.

View solution in original post