AJAX - Comment Box with [ Javascript jQuery JSON PHP MySQL ] - Step by Step How to Guide - Part 14 HD

20.03.2013
In this tutorial we create the database tables. I am using phpmyadmin to administer the database tables. As much as I dont like to use phpmyadmin, I decided that it would be easier in this video series. So we have to create 2 tables, one for the user - subscribers and the other table for the comments which has been entered. We need to have subscribers table so as we know which person is logged on. The table for the users is not particulary the best one but in this scenario it was just there to have the persons userId and name. In a real time comment box you would have then the password and username stored in there, possibly also then the date of last being logged. The comments tables, simply has the comment_id as the primary key and then the userId who has entered the comment and then the comment text itself. Its always as good idea to save the sql which you enter just in case you want to then move your database to another server one day. This means then that you know the exact table format which you used before. With database tables, its better to keep it as simply as possible, and if you need to multiple columns then make them. Dont take shortcuts with databases tables, as it always takes longer to process the information later, if you try to shortent things using less columns. We also then start to make the Models for the tables. A model is basically the business logic for the data side of the website. We want to know that all data comes from one place and is not spread all over the website files. We make 2 classes, one for the Comments and the other for the Subscribers. They will each manage inserting, updating and deleting data from the relevant table. I have many tutorials about classes and objects in php, so if you dont understand what a static method or function is then I really recommend watching my other tutorials. We also then make some defines, in the defines file, this is so as our code knows where the Models directory is. As discussed previously, its good practise to always keep the logic controlled in one place, therefore is you change the file or directory structure later, then you only have to change the defined variable constant rather than many files. When then start to write our insert methods to start to insert data in the databases.

Похожие видео

Показать еще