Source : ct|08.01.09
< Tutorials Computer, Multimedia, Chinese
In this tutoriel we will create a mysql database intended to be used with a php page. For this we will suppose that you have
already installed easyphp on your computer
If you have not already installed it, the tutoriel How to install and use
Easyphp shows you how to proceed.
We will take the example of a database named "test" including a single table called "visiteurs". This table will be
constituted with 3 fields. A field named "id" constituting an index and two text fields named "nom" and "motdepasse".
This tutorial includes three parts:
1) Useful informations;
2) Create a mysql database;
3) Create a table in a mysql database.
The storage engine:
When we create a mysql database, PHPMYADMIN asks to choose a storage engine (isam, innodb, csv...) for this database. The
storage engine "isam " presents the advantage to be permformant and easy to administer. With this engine, every table is
represented with a file for the structure (.frm ), a file for the datas (.myd ) and a file for the index
(.myi ) placed in the directory "mysql/data" of easyphp.
The collation
It is useful to understand the difference between the standards ISO-8859-1 and unicode.
The standard ISO-8859-1 is very used. It is sometimes called Latin 1. In this standard, every character is coded with a byte ( 8 bits).
We notably meet:
- latin1_bin : latin1 binary encoding;
- latin1_general_ci : multilingual encoding;
- latin1_general_cs : multilingual, case sensitive encoding;
- latin1_swedish_ci : encoding for Swedish / Finnish.
Unicode constitutes an extension of this characters set, allowing to code every character on 2 bytes to be able to take into
account the characters of the Asian, Arabic, Russian or oriental languages for example. UFT-8 is an encoding allowing the
exchange of texts constituted by unicode characters.
Open the administration tool phpmyadmin.
Create a database named "test" for example.
This base does not still contain a table.
In the data base create a table named "visiteurs" for example. Attribute 3 fields "id", "nom" and "motdepasse" for example at this table.
Attribute to the field "id" the properties primary index, unsigned and automatic incrémentation ( A_I) for example.
Attribute to the fields "name" and "motdepasse" the text type varchar(15) for example.
Set the storage engine "MyISAM" and a collation "latin1_general_ci", for example. Then click the button "Sauvegarder",.
The corresponding sql instruction, generated automatically by phpmyadmin, is the following one:
CREATE TABLE `test`.`visiteurs` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `nom` VARCHAR( 15 ) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL , `motdepasse` VARCHAR( 15 ) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL ) ENGINE = MYISAM CHARACTER SET latin1 COLLATE latin1_general_ci
The corresponding files are immediately created in the directory "EasyPHP 3.0/mysql/data/test":
- db.opt : characteristics of the database "test";
- Visiteurs.frm : structure of the table "visiteurs";
- Guests. MYD : datas of the table "visiteurs";
- Guests. MYI : index of the table "visiteurs".
This database is now installed and ready to be used with a php program.
© http://turrier.fr (2007) |