- Messages
- 27
- Reaction score
- 0
- Points
- 26
PART 2 OF PHP/MYSQL PROGRAMMING
CREATING DATABASE
siguro alam na din ninyo gumawa ng database..
Sa Access gumawa na din kayo or sa MSsQL, Oracle and any other DBMS...
ang gagamitin natin dito ay napaka obvious sympre PHP using PhpMyadmin and MySQL script....
So...Start tayo sa phpmyadmin...naka gawa na tayo ng DB..next step ay gumawa ng ROW/COLUMNS...
Meron tayong four Fields in your table from the previous section. Although they are set out in rows in the images, the rows are actually the Columns you saw earlier – the Fields. Each Field needs a name. So go ahead and type the following for your Field names:
So we have given each column in our table a name: ID, First_Name, Surname, and Address. The next thing to set is what type of data will be going in to each field - do you want to store text in this field, numbers, Yes/No value, etc?
ID – A number, used just to identify each record. This needs to be unique for each record
First_Name – VARCHAR
Surname – VARCHAR
Address – TINYTEXT
For our fields, then, we'll use the following Types:
ID -SMALLINT
First_Name -VARCHAR
Surname -VARCHAR
Address -TINYTEXT
So select these from your Types drop down list:
We've only set Lengths for the VARCHAR TYPES. If you leave it blank for VARCHAR, you'll get a default value of 1 character.
The other Field settings we'll take a look at are these:
Null
This is an important field in database terminology. It essentially means, "Should the field contain anything?" If you set a field to NOT NULL, then you can't leave it blank when you come to adding records to your database. Otherwise you'll get errors.
Default
Do you want to add anything to the field, just in case it's left blank when adding a record? If so, type it in here.
Extra
This is where you can set an auto increment value. This means adding one to the previous record number. This is ideal for us, as we have an ID field. Then we don't have to worry about this field. MySQL will take care of updating it for us.
The three icons are Primary Key, Index, and Unique. Primary keys are not terribly important for flat-file databases like ours. But they are important when you have more than one table, and want to link information. They are set to unique values, like our ID field. An index is useful for sorting information in your tables, as they speed things up. Unique is useful for those fields when there can't be any duplicate values.
So, set a primary key for the ID field by selecting the radio button, and choose Auto Increment from the Extra drop down list:
Your field screen then, minus the parts we've ignored, should look like this:
Click the Save button on the fields screen. You'll be taken back to the Structure screen. There should be a lot more information there now. Don't worry if it looks a bit confusing. All we want to do is to add one record to the table. We'll then use PHP code to add some more.
PART I: http://www.symbianize.com/showthread.php?t=323502
-----------------------------------------
END OF PART II
big credits to: homeandlearn
Last edited: