2

Creating databases & tables

September 19, 2022
Share

Welcome to this section of interacting with databases. What makes PHP a very powerful language is its ability to enable users interact with the databases i.e. inserting data, retrieving data, deleting and updating data in the database—CRUD (Create Retrieve, Update, Delete) operations. To perform such operations, we need to first have a database and tables where we can store data to be operated on. In this post, we are going to learn how we can create databases and later on tables.

Creating databases

Not all of us are good at SQL, and therefore, we are going to use the graphical tools that come by default with MySQL in WampServer for us to finish the task so fast. Launch WampServer from the list of installed programs and look for PhpMyAdmin.

This menu item provides us with an interface for creating tables and databases with graphical tools.

On the left side of the phpMyAdmin panel is where all created databases are found. To create a new one, click on the New icon and an interface showing where the database name detail is provided. Enter the name of the database you wish. For our case, let us call it visitors. Click create and the database will be created. You can see it is now part of the available databases.

That is how we create databases in MySQL environment using the graphical tools. For my friends who are command line die-hards, we issue the code below using the MySQL Console that is accessed from the MySQL control panel under MySQL (Check out the first screenshot on this page)

Creating Tables

After we have created the database, now let’s create a table called feedback with only 2 columns i.e. name whose data type is varchar and the maximum length is 100 characters and feedback column whose data type is varchar and the maximum length is 500 characters.

To do this task, we click on our database name and a new interface for creating tables will be provided. Enter the name of the table which is feedback and in the number of columns put 2. Then click Go.

After clicking Go, you’re provided with an interface to allow you enter the column details for the table. Enter the column details specified above and click Save.

After that, we have now we have successfully table feedback in the visitor database. Congratulations 🍾. You can go on and practice with creating other databases and tables. Try exploring how to use primary key and auto increment features. You can visit my earlier post on creating tables in SQL for a more understanding of some concepts.

Back To Top