Creating a Database
Home Courses Community Support
Creating a Database

There's little doubt that the tremendous popularity of PHP is due in large part to its ability to easily utilize a wide variety of powerful database systems. Adding a database to a website can provide the means for great dynamic content, all kinds of user interactivity and a range of flexibility and manageability that could not easily be accomplished without it. Sounds great. But what exactly is a database? let's explore-

A database is a collection of data that is stored independently of the manner in which you collect it or may wish to retrieve it. It is organized for efficient storage and retrieval, based on the nature of the data, rather than the collection or retrieval methods. The use of database in web application can be understood by:

  • Forums: Hundreds of forums (message boards) on the internet are run using PHP and MySQL. These are much more efficient than other systems that create a page for each message and offer a wide variety of options. All the pages in the forum can be updated by changing one script.

  • Websites: If you have a large website and you want to change the design it can take a very long time to update and upload all the pages. With PHP and MySQL your whole website could be just one or two PHP scripts. These would access a MySQL database to get the information for the pages. To update the website's design you would just have to change one page.

Let's create a database-

For PHP we use MySQL. It is most popular database used for PHP. If you have hosting for PHP website i.e. linux hosting then procedure of creating a database will be same for live server and for your local host.

  • Now to create database on your local host, open it and click on PHP My Admin from left side menu. You will get a page like below image-

  • Click on Databases on top. You will get a field to enter database Name. Next to it you will get a dropdown. Let the dafault value selected i.e. Collation.>

enlightenedGiving database a name relevent to it's use is a good practice. For example you can create database with the name of website for which it will be used.
  •  Enter Database Name and click on Create.

You have successfully created your database. But it is empty as it does not have tables.

enlightenedAll the data we save in database is saved in form of tables.

To save our form data in database, we need to create a table which will have all the fields of web form.

  • To create a table, select your database name from left side menu. You will get a field to enter table name. Enter the table name and the number of column the table will have and click create.

enlightenedNumber of column depends on the data you will save in table. For example, we require five column to save Name, Email, Phone and Message. One extra column is to give a unique id to each entery inserted in database. It make everything easy when we work on large database. Moreover, you can add any number of column later.

  • We have entered table name form_data and the number of column five.
  • Now you will get fields to enter column name, data type for particular column, length of data entered and many more.
  • Enter field name, type, and length for particular column.

enlightenedFor ID we have used auto increment. It will increase the value of ID automatically and we will have a unique ID for each entry.


  • Structure of the table will be as below-

  • You can add more tables by selecting create table from left menu.

Well, you have created your database and table successfully. Now to use this database, you need to connect this database to website. We will learn to create connection in next heading.


← Preview

Integrate Mail Function within Form

Next →

Connection to Database


Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.


  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App