Problems:
Write down the procedure of creating database and table in MySQL database. 2015,2010,2014,2017,2018

Creating a new database & Table in mysql

<?php
$server_name = "localhost:3308";
$db = "tufan";
$user_name = "root";
$pass = "";

//Create Connection
$conn = new mysqli($server_name,$user_name,$pass,$db);

//Check Connectio
if(!$conn){
die ("Database problem!!!");
}
else{
echo "Connection Ok";
}

//create a database named DB
$a="CREATE DATABASE NEWDB";
if($conn->query($a)===TRUE){
echo "Database Create successful";
}
else{
echo "error";
}
$conn->close();

// Create a table
$sql= "CREATE TABLE boss(
id INT(3) PRIMARY KEY,FastName VARCHAR(12) NOT NULL,LastName VARCHAR(10) NOT NULL)";

if($conn->query($sql)===TRUE){
echo "Table create ok";
}else{
echo "faild";
}
$conn->close();
?>


Post a Comment

Previous Post Next Post