Home > AI > Language > PHP > mysqli >

create a database

Working code:

$db_host = "";
$db_user = "";
$db_password = "";
$db_dbname = "";


// Create connection
$con = new mysqli($db_host, $db_user, $db_password, $db_dbname);
// Check connection
if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}




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

Leave a Reply