• Have Any Question?
  • contact@eitworld.com

MySQLi Create Table





Create Table In MySQL by using the create command of MySQL. You have to define the table name and field name with data type and size to create the table.

How to Create Tables in MySQL:

the following syntax is used to Create Table in MySQL:

Create table table_name(field1 (size), field2(size), fieldN(size));

Example:

Create Table in MySQL

Create table user (user_idint(10), user_namevarchar(20));

You can learn Create Table in MySQL from eitworld.com in easy way with explained examples.

  • After creating a database, tables are to be created to insert the data.

Creating Table

  • To create a table in MySQL, use CREATE TABLE statement.

Syntax

CREATE TABLE tablename(columnName1 datatype,columnName2 datatype,…)
  • Some of the datatypes that MySQL use are-
    • integer- For integer type data. (1, -50, 50, 846 etc.)
    • real- For real type data. (2.35, 4e3 etc.)
    • text- For plain text.
    • char[number]- For fixed number of characters. (char[50])
    • varchar[number]- For variable number of characters. (varchar[50])
  • This statement must be added to php function mysqli_query(), which is used to execute all the queries in MySQL. Queries are discussed in the chapter Introduction to MySQL.
  • Before creating a table, a database must be connected. We are connecting the database firstdb and we will create the table inside it.

<!DOCTYPE html>
<html><body><?php

$connect=mysqli_connect(“localhost”,”root”,””,”firstdb”);

$table=”CREATE TABLE employee(

id integer,

name char(50),

salary integer,

contact text

)”;

mysqli_query($connect,$table);

?>

</body>

</html>



Real Time Web Analytics