MySQL Database

hi, please tell me what am I doing wrong when trying to create a database from PHP (im try test it on subdomain index.php) ? DB not created.

index.php
<!DOCTYPE html>
<html>

<?php
$servername = "sql307.infinityfree.com";
$username = "epiz_xxxxxxxxx";
$password = "xxxxx";

// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Create database

if (mysqli_query($conn, "CREATE DATABASE qwerty123")) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . mysqli_error($conn);
}

mysqli_close($conn);
?>

</html>
1 Like

Welcome

You cannot create databases that way, you have to use PHPMyAdmin to do that. (My bad - I meant the “MySQLDatabase” section in the control panel, or the client area)

Also, when creating a connection, you have to specify the database name (hance why it cannot be created via PHP)

6 Likes

thanks for answer :grinning:

2 Likes

Not phpMyAdmin, but the control panel or client area.

You cannot create databases from your own SQL code, it must be handled through our systems to ensure the correct naming scheme, database permissions and so on are correctly set up.

4 Likes

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