Create table in mysql with PRIMARY KEY AUTO_INCREMENT using php

<?php

// CreateTable.php  [ali-mirza.blotspot.com]

$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'mydb';

$con = mysqli_connect($host, $user, $pass, $db);

if(!$con){
    die('Connection Error!');
}else{
    $sql = "Create Table user("
            . "id int NOT NULL AUTO_INCREMENT,"
            . "name nvarchar(20),"
            . "email nvarchar(20),"
            . "ph varchar(11),"
            . "PRIMARY KEY (id))";
    $result = mysqli_query($con, $sql);
    if($result){
        echo 'Table Create successfully';
    }else{
        echo 'Table Not Created';
    }
}

2 comments:

  1. In the mysqli_query is first parameter sql and second db connection. You have this conversely.

    ReplyDelete
    Replies
    1. In mysql_query() first parameter is Sql and second is Db but
      In mysqli_query() first parameter is Db and Second is Sql .
      thanks for reading post, for any question contact us

      Delete