db creating script not working

//step 1
$servername = "sql112.epizy.com";
$username = "epiz_23164233";
$password = "controlpanel password";
$mydbname = "epiz_23164233_myjobsite1";

// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
echo "Connected successfully.";
///////////////////////////////////////////step 1 end successfully

//step 2 begin from here

// Create database

$sql = "CREATE DATABASE $mydbname";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . $conn->error;
}


and output is 

Connected successfully.Error creating database: Access denied for user 'epiz_23164233'@'192.168.%' to database 'epiz_23164233_myjobsite1'

please help me where iam wrong tell me.
  • The $password should be your mysql db password, not control panel (if you set them both different).
    - Then, in  conn = new mysqli(), seems like you forget to write your database. The format should be:
    $conn = new mysqli(host, username, password, dbname)
    - You can’t query CREATE DATABASE through script because it’s kinda restricted ( most of shared hosting provider would do the same). CREATE TABLE is possible though

joo_nath you are correct it may be because shared hosting… id and password is correct but
it may be possible  “create database” is restricted because i am using shared hosting.   correct me if iam wrong. 

thanks.

Please note that it’s not possible to create databases from PHP in shared hosting. You can only create new databases through the control panel.