Create a database and table in MySQL
Simply hit http://localhost in your browser, it’ll redirect you to the URL http://localhost/xampp, look for phpMyAdmin under Tools menu in the left, click on phpMyAdmin, it’ll take you to the MySQL Administration interface which is developed using a free and open source software called phpMyAdmin (most downloaded application in SourceForge). Change the language to English under Appearance Settings if it’s already not English. Click on Databases menu from top left in the middle panel (just below localhost icon). Type the name of your database in Create Database text box, I’ll name it as bittu, don’t change anything in the collation box. Hit Create button. Select your database from the left panel by clicking on it you’ll see the option to create table, you can either use the interface to you create table and fields in the table or you can use a SQL QUERY. Construct the QUERY and paste in on SQL box, hit Go button. I’ll rather write a QUERY because that is a faster method to create a table. Below is my SQL QUERY.
[bash]
CREATE TABLE `users` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(50) DEFAULT NULL,
`lastname` varchar(50) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`pssword` varchar(32) NOT NULL,
`created_time` timestamp DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(3) DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
[/bash]
Bingo! You have created your first MySQL database table. Now lets enter some data into it. Again you can use the phpMyAdmin interface to enter data into the table or you can use SQL QUERY. I’ll use SQL QUERY.
[bash]
INSERT INTO `users`(`uid`, `firstname`, `lastname`, `email`, `pssword`, `active`) VALUES (”,’Bittu’,’Sharma’,’bsharma@xyz.com’,MD5(‘admin’),’1′);
INSERT INTO `users`(`uid`, `firstname`, `lastname`, `email`, `pssword`, `active`) VALUES (”,’Kamalika’,’Roy’,’kroy@abcd.com’,MD5(‘admin123′),’1’);
[/bash]
We have successfully entered two records / rows into the table. Next step is to fetch / retrieve this data from the table using PHP code.
Leave a Reply