Cours: Conception et programmation de
sites web dynamiques
Programmation Web coté
Server avec PHP/MySQL
2me partie
(English)
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Content
● MySQL server installation
● Introduction to web databases
● Lab: Using PHP with MySQL
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
MySQL server installation
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Testing whether or not MySQL is
working
To test whether or not MySQL is working,
you can execute the following commands:
C:\mysql\bin\mysqlshow
C:\mysql\bin\mysqlshow mysql
C:\mysql\bin\mysqladmin version status
proc
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email: [email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Setting your PATH
Deleting the anonymous user
Setting the root password
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Setting your PATH
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Setting your PATH
Double-clicking
PATH will allow
you to edit it.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Setting your PATH
Add a semicolon to the end of your current
path to separate your new entry from
the previous one then add c:\mysql\bin.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Setting your PATH
When you click OK, your addition will be
stored in the machine’s registry. Next time
you restart the machine, you will be able
to
type mysql rather than C:\mysql\bin\mysql.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Deleting the anonymous user
c:\mysql\bin\mysql
use mysql
delete from user where User='';
quit
c:\mysql\bin\mysqladmin reload
The anonymous user is now gone.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Attending the loose ends of the
default configuration
Setting the root password
Even the superuser account, root, has no
password yet.To set this user’s password
type
these lines:
c:\mysql\bin\mysqladmin -u root password
your_password
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Introduction to web
databases
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Using a relational database allows you to
quickly and easily answer queries about
what are the options of studies at UP,
about the students, which options is
chosen by most students, etc..
This information can help who visits the
web site of the university and improve the
site to attract and keep more users
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational database concepts and
terminology
Web database design
Web database architecture
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Tables
Relational databases are made up of
relations, more commonly called tables. A
table is
exactly what it sounds like: a table of data.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Rows
Each row in the table represents a
different customer. Because of the tabular
format, they
all have the same attributes. Rows are
also called records or tuples.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Keys
We need to have a way of identifying
each specific record. Names usually
aren’t a very
good way of doing this - if you have a
common name, you’ll probably
understand why.
The identifying column in a table is called
the Eng.
Author: keyRodrigue
or the primary key.
OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Schemas
The complete set of the table designs for
a database is called the database
schema.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Relationships
Foreign keys represent a relationship
between data in two tables.
Three basic kinds of relationships exist in
a relational database.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Relationships
They are classified according to the
number of things on each side of the
relationship. Relationships can be either
one-to-one, one-to-many, or many-to-
many.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Relationships
A one-to-one relationship means that there
is one of each thing in the relationship.
In a one-to-many relationship, one row in
one table is linked to many rows in another
table.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Relational Database Concepts
Relationships
In a many-to-many relationship, many rows
in one table are linked to many rows in
another table.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
How to Design Your Web Database
Think About the Real World Objects
You Are Modeling.
Avoid Storing Redundant Data.
Use Atomic Column Values.
Choose Sensible Keys.
Think About the Questions You Want
to Ask the Database.
Avoid Designs with Many Empty
Attributes.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Web Database Architecture
The client/server relationship between a Web browser
and Web server requires communication.
The basic Web database architecture consists of the
Web browser,Web server, scripting engine, and
database server.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Using PHP with MySQL
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Connection to a database
<?php require("connections/cn.php")?>
<?php
$db_host="localhost";
$db_user="doncurt";
$db_password="passwd";
$db_name="test";
?>
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email: [email protected] / www.tele-matica.net
Connection to a database
$mysql_cn = @mysql_connect($db_host,
$db_user, $db_password) or die("La
connection n'a pas été établie");
mysql_select_db($db_name);
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Query a database (Insert)
$sql_query = "insert into
Tb_UPSt(Id_St,nom,age,carriere)
values('NULL','$nom','$age','$carriere')";
mysql_query($sql_query);
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Query a database (Select)
$sql_query = "select * from Tb_UPSt";
$result = mysql_query($sql_query);
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Displaying data
For
($i=0;$i<=mysql_num_rows($result);$i++)
{
$dis_nom=mysql_result($result,$i,
"nom " );
$dis_age=mysql_result($result,$i,
"age " );
$dis_carriere=mysql_result($result,$i,
"carriere" );
Author: Eng. Rodrigue OSIRUS
} 3700 7443, email: [email protected] / www.tele-matica.net
Tel: (+509)
Conclusion
We have seen the installation procedure
of MySQL under a windows environment
and we covered the most important
concepts of web databases.
We are ready to use some PHP codes
with MySQL to query our databases. This
will be done in the Lab following this
section.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net
Literature
● http://www.commentcamarche.net
● PHP and MySQL web development 2nd edition,
Luke Melling and Laura Thompson.
Author: Eng. Rodrigue OSIRUS
Tel: (+509) 3700 7443, email:
[email protected] / www.tele-matica.net