<?php
//connect with the server
//declare variable of the server, user, password
$servername = "localhost";
$username = "root";
$password = "";
//connection query
$conn = mysqli_connect($servername, $username, $password);
//check connection query
if(!$conn)
{
die("Error to connect with the server: " . mysqli_error($conn));
}
else
{
echo "Successfully connected with the server";
}
//How to create database after connection
$query = "CREATE DATABASE myDD";
$result = mysqli_query($conn, $query);
//check the query for create database
if(!$result)
{
die("error to create a database: " . mysqli_error($conn));
}
else
{
echo "Successfully create a database";
}
//How to create table after successfully create a database
$db = "registration";
$db_query = mysqli_connect_db($conn, $db);
$sql = "CREATE TABLE users(
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL)";
//check the create table query
$result = mysqli_query($conn, $sql);
if(!$result)
{
die("error to create a table: " . mysqli_error($conn));
}
else
{
echo "Create table successfully";
}
//insert data into table
$insert = "INSERT INTO users(name, email, password) VALUES('user', 'user@gmail.com', 'user_address')";
//check query
if(mysqli_query($conn, $insert))
{
echo "Succesfully inserted the data";
}
else
{
die("Error to insert the data" . mysqli_error($conn));
}
?>

No comments:
Post a Comment