Create Table mysql using php



C1 (Name)C2 (Age)C3 (Weight)
R1R1 C1 (John)R1 C2 (21)R1 C3 (120)
R2R2 C1 (Big Sally)R2 C2 (27)R2 C3 (400)
R3R3 C1 (Tiny Tim)R3 C2 (6)R3 C3 (35)
R4R4 C1 (Normal Ned)R4 C2 (35)R4 C3 (160)

Before you can enter information (lines) into a table, you should first characterize what sorts of information will be put away (sections). We are currently going to outline a MySQL inquiry to summon our table from database arrive. In future lessons we will utilize this table, so make certain to enter this question effectively!

PHP & MySQL Code:

<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Create a MySQL table in the selected database
mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
 name VARCHAR(30), 
 age INT)")
 or die(mysql_error());  

echo "Table Created!";

?>

Display:

Table Created!

'id int not null auto_increment'

Here we create a column "ID", which adds a new entry each time to the table. Previously, the id = 1 in the table, the second line id = 2, the third line id = 3, and so on.

The column "id" is nothing that we need to worry after creating this table, because it is automatically calculated in MySQL

INT - stands for integer or whole number. 'Id' is defined as an integer
No Taps - These are actually two keywords, but together they say that this column can not be empty. There is no entry faucet, if it has some value, while no value is available.
AUTO_INCREMENT - A new entry is added every time, value will increase by 1

primary key (id)
Primary KEY is utilized as a one of a kind identifier for the lines. Here we have made "id" the PRIMARY KEY for this table. This implies no two ids can be the same, or else we will keep running into inconvenience. This is the reason we made "id" an auto-increasing counter in the past line of code.

name varchar(30)
Here we create a new column with the name "name"! VARCHAR stands for "variable character" "Character" means that you can enter any type of information entered in this column (letters, numbers, symbols, etc.). This is "variable" because it can adjust its size to store the number of 0 characters and a specified maximum of characters.

We will most likely store the letter (AZ, AZ) just to use this name. The maximum number of characters in the number inside the bracket is determined. In this case, the maximum is 30.

'or die(mysql_error());'

If there is a problem in the table creation process, it will print an error


Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment