Skip to main content

PHP Tutorial–Lesson 4: Introduction to PHP- Part III

•Today, I’ll put you in a project, and try to analyze it step by step Smile 

•Suppose, a customer has a company, and asks you for a method for storing his employee information, and accessing it when needed.

•You should put in mind, that your customer in best case has minimum knowledge about databases, and all what he need is what, not how.

•Its your turn to ask the customer, about nature of data he wants to collect.

•Let’s say the customer told you he wants to store employee name, social number, department, job title, salary, cv, telephone, address.

•These little words from your customer, helps you imagine how your table structure will look.

Analysis Step:

•Analysis step simply means determining proper data types for data you are going to collect.

•Let’s start:

•Employee name: name its proper data type is string, it is possible to make its type text or longtext, but we want to design quick, suitable, and with the less cost that meets requirements for our table.

•Social number: social number consists of number of bits, so int is suitable, we might thought about double here, but remember that double and float are used when your number consists of decimal numbers. So best choice here is int.

•Department: might be int or string! Because, some companies label their departments by numbers for example: department 1, department 2… etc. and some companies might label their departments by name, for example: Computer department, Human Resource department… etc.

•Job title: string, possible values: administrator, manager, head-master, consultant… etc.

•Salary: double.

•CV: text, we might thought about string, but in fact, string is not enough, because cv’s sometimes are big, and might contain from more than one page, so string does not meet your customer requirement, longtext is true, but is too big. We might not use all the storage offered by longtext.

•Telephone: int, but I prefer string, because you might separate post-code from number by dash - .

•Address: string.

•What else?

•Your customer told you all information he want to collect about his employees. But there still another thing, will help you in your application, and facilitate your job, which is, give each employee an id.

•This id must has a properties of uniqueness, numerical and increments.

•Why?

•Uniqueness: this id should be unique, to differ each employee from another. if you work in a company that has more than 100 thousands of employees or customers, you will notice that there might be high similarity in some names. so you can’t differ one from another. But when you deal with numbers no way to find two numbers identical.

•To make id unique, its type should be int and has a property of incrementing.

Design Step:

Once we had analyzed our customer inquiry. Then it is the time to design our table, or in other words, create our table.

CREATE TABLE employee

(

id int  AUTO_INCREMENT,

PRIMARY KEY(id),

name varchar(150) NOT NULL,

socialNo int NOT NULL,

department varchar(100) NOT NULL,

jobTitle varchar(50) NOT NULL,’

salary double NOT NULL,

cv text,

telephone varchar(25) NOT NULL,

address varchar(200)

)

Notes:

•CREATE TABLE: a query known in MySql db, its function is creating a table, in our example it creates a table called employee.

•Table attributes (columns) enclosed within parenthesis () and each attribute except last is followed by a comma.

•NOT NULL: means that this info must be filled with suitable data. We use it where an attribute must has a value. If it does not matter whether this field has value or not, we don’t write NOT NULL.

•AUTO_INCREMENT: means that this is a counter and increments on every insertion to the table by one.

•PRIMARY KEY: means this field value should not be repeated in any row. ( unique)

•Each table has only one primary key. And this field cannot be null.

•varchar: tells the db that this field value is character, and maximum size of character is determined by integer number. varchar(25) means this field is a string that at most its length is 25 character.

•Cv, and address fields might be null.

Previous Query will generate an empty table looks like this one.

image

To download this lesson click here: PHP Tutorial–Lesson 4: Introduction to PHP- Part III

Best Wishes,

Anas Jaghoub

Comments

Popular posts from this blog

PHP Tutorial–Guest Book–System Definition and Requirements

In this lesson I’m going to illustrate the system definition and requirements for the Guest Book application. It is an important step in developing any application, since this step gives us an orientation about the system and its functionality, what is expected from the system to do. actually the system definition comes from keywords from customers and end users, usually try to make it clear for what they need in the application, and what they expect the system to do.  As developers it is our role to define the requirements for the system to be developed. In our example the system definition for the Guest Book is: A system that allows visitors of the site to post their comments and feedbacks about the site, with the possibility for managing comments and maintain it easily and user friendly. On the other hand, the system requirements are: a web server, since it is clear that the developed system is going to run on the Internet, so it is a web-based application not windows-based.

تعلم تطوير تطبيقات للموبايل باستخدام الأندرويد

مرحبا أصدقائي يسعدني أن أبدأ معكم سلسلة حلقات في تعلم تطوير تطبيقات للموبايل باستخدام الأندرويد ، وسأسعى جاهدا معكم في أن تكون هذه السلسلة من أوائل السلسلات في اللغة العربية لتعليم برمجة تطبيقات الأندرويد من البداية وحتى الاحتراف. وسأحاول قدر المستطاع الشرح بلغة عربية بسيطة ومفهومة. حيث ستكون غدا إن شاء الله الحلقة الأولى من تعلم تطوير تطبيقات الموبايل باستخدام الأندرويد. أنس الجاغوب Twitter: @anasjaghoub Facebook: anasjaghoub

Web Development Best Practices (PHP Best Practices)

Websites development is one of the most challenging projects ever to develop, according to the large number of components you deal with, integrate, and manage in your application. For example, most web projects Deal with databases as their data source, and I ntegrate with external services called web services and APIs. As well the application M anages its own objects and components from views to models to controllers to plugins and so on. A skilled web developer should have a great/deep knowledge in most of components used in his system, and as well should ha ve intensive focus on how each component work and how can be used, what can be done, and what cannot. On the other hand, the huge amount of requirements, components to manage, and time frame given to you to accomplish your mission, and number of people in your team, all these factors together requires from you to organize your tasks, and priorities your requirements, do deep analysis and planning in order to have a hi