Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
886 B
1
Indexable
Never
<?php
    $host = "localhost";
    $username = "root";
    $password = "";
    $db = "donbosco";

    $conn = new mysqli($host, $username, $password);

    if (!$conn->connect_error) {
        echo "<b>Connection Established!</b><br>";
    } else {
        die ("Error: ".$conn->connect_error);
    }
    
    
    $sql = "create database donbosco";
    try {
        $conn->query($sql);
        echo "<br>Database created";
    } catch (\Exception $e) {
        echo "Database already exists<br>";
        echo "Using database<br>";
        $conn->close();
        $conn = new mysqli($host, $username, $password, $db);
    }
    
    $sql = "create table bca(deptid int, dept_name varchar(80))";
    try {
        $conn->query($sql);
        echo "<br>Table created!";
    } catch (\Exception $e) {
        echo "<br>Table already exists<br>";
    }
?>