Defining Tables

If you have phpmyadmin (or similar) available then you might be tempted to use the option there for creating the new tables for your database. You should resist that temptation.

Should you enter the create table instructions directly into a utility like that you make things much harder for yourself should you ever have a need to recreate the same table.

If you have made that mistake then it isn't the end of the world since you can use the phpmyadmin export panel to export a copy of the mysql commands for creating your tables.

What I do recommend that you do at the very least is to open a text editor first instead of going directly into phpmyadmin. You can type in the actual mysql create commands that you need there and save them. To actually create the tables you can open phpmyadmin and go to the SQL tab then copy the content of your text file and paste it in there in order to run the commands. That way if you need to start over you can drop all the tables and recreate them again simply by copying and pasting the commands rather than having to remember exactly what to enter where to recreate what you already had.

The solution that I actually prefer to use is to wrap the mysql commands inside of some PHP so as to create a script that will both drop and recreate all the tables whenever that script is loaded into the web browser. This has several advantages.

Of course you don't want to leave this PHP on a live server where anyone can access it. That doesn't mean that you can't temporarily upload it to your web hosting when you are ready to go live and simply delete it again after you have run it. I find that is the easiest way to get the live server configured appropriately after I have finished testing.

Whichever way you decide to go the important thing is to keep a copy of the mysql commands that are needed to recreate the tables in your database. That way if you ever find a need to recreate the tables either on the same server or a different one you have the information readily available to do it quickly and easily.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow