Esküvő

MySQL Create Table Query

To learn how to use MySQL queries first create a database. The database name is students and there are four columns id, first_name, last_name and gender.

Id is integer has an auto increment property which means, every row will have different number for id.
First_name, last_name  varchar, it can contain 50 characters.
Gender is varchar, but maximum 6 characters allowed, because it will only have male or female for value.

The following code will create the students database if it is not exists.

MySQL Create table

CREATE TABLE IF NOT EXISTS `students` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
  `last_name` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
  `gender` varchar(6) COLLATE utf8_hungarian_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci AUTO_INCREMENT=1;

Create MySQL table with PHP

To execute MySQL query in PHP is easy, write the following code and replace CODE with your MySQL query:

<?php mysql_query("CODE"); ?>
<?php
mysql_query("
CREATE TABLE IF NOT EXISTS `students` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
  `last_name` varchar(50) COLLATE utf8_hungarian_ci NOT NULL,
  `gender` varchar(6) COLLATE utf8_hungarian_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci AUTO_INCREMENT=1;
");
?>

Result

The result is an empty database.

idfirst_namelast_namegender
       

Next to read

The next article is about MySQL Insert Query, and you learn how to insert rows to the database.


Esküvő


Related articles

Email Validation

Email Validation

08/02/2013

Learn how to validate email on client side with HTML5, Javascript and on server side with PHP.

Generate Thumbnail on the Fly with PHP

Generate Thumbnail on the Fly with PHP

04/02/2013

In a previous artice I already showed you how to generate square thumbnails with PHP. Now I show you how to keep the original ratio of the image and how to control the alignment of the square image.

Facebook Upload Photo to User′s Profile

Facebook Upload Photo to User′s Profile

31/01/2013

Learn how to upload a photo to Facebook user′s profile with PHP SDK via Graph API!


1 comment

jtag2012-12-08 00:13

Really good post, helped me a lot. Thank you.

Leave a comment

We welcome any comment from you! Please keep in mind that comments are moderated and rel='nofollow' is in use. So, please do not use a domain as your name or a spammy keyword, or your comment will be deleted.

Name: *

E-mail: *

Message: *

Click on the car *


Find us on Facebook

Tags

Esküvő

Back to Top