Wednesday, November 27, 2019

How to create a database in php using mysql

Tags:
create a database in php, php tutorial, how to create database in php, use mysql create database in php,php with mysql, create datbase example in php, code create database in php, php example, code php example,how to code php example, php create database example.
How to create a database in php using mysql

Introduce create database in php
To create and delete a database you should have admin privilege. Its very easy to create a new MySQL database. PHP uses mysql_query function to create a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
Performed create database in php
Step 1. Connect php to mysql
   $localhost ="localhost";
    $user = 'root';
    $password ="";
   
    $conn = mysqli_connect($localhost,$user,$password);
    if($conn){
        echo " connect success";
    }
Step 2. Performed create database
$SQL = "create Database test_db_mysqli";
     $review = mysqli_query($conn, $SQL);
     if(!$review){
         echo " Create database error " .mysqli_error();
     }
     echo " Create database successfull";
All code create database in php below;
<html>
 
   <head>
      <title>How to Create database in php using Mysqli</title>
   </head>
 
   <body>
 
   <?php
    $localhost ="localhost";
    $user = 'root';
    $password ="";
   
    $conn = mysqli_connect($localhost,$user,$password);
    if($conn){
        echo " connect success";
    }
     $SQL = "create Database test_db_mysqli";
     $review = mysqli_query($conn, $SQL);
     if(!$review){
         echo " Create database error " .mysqli_error();
     }
     echo " Create database successfull";
   ?>
   
   </body>
 
</html>

No comments:

Post a Comment