PHP and MySQL Dr. E. Benoist Winter Term 2006-2007 PHP and MySQL - - PowerPoint PPT Presentation

php and mysql
SMART_READER_LITE
LIVE PREVIEW

PHP and MySQL Dr. E. Benoist Winter Term 2006-2007 PHP and MySQL - - PowerPoint PPT Presentation

Berner Fachhochschule - HTI PHP and MySQL Dr. E. Benoist Winter Term 2006-2007 PHP and MySQL 1 PHP and MySQL Introduction Basics of MySQL Create a Table See the content of a DB Tables: Change rows and Insert data Select


slide-1
SLIDE 1

Berner Fachhochschule - HTI

PHP and MySQL

  • Dr. E. Benoist

Winter Term 2006-2007

PHP and MySQL 1

slide-2
SLIDE 2

PHP and MySQL

  • Introduction
  • Basics of MySQL

Create a Table See the content of a DB Tables: Change rows and Insert data Select Information

  • PhpMyAdmin
  • PHP and MySQL together

mysql mysqli Pear DB Library

  • Conclusion

PHP and MySQL 2

slide-3
SLIDE 3

PHP and the Data Bases

MySQL syntax

◮ Create a new Data Base ◮ Set the rights for a DB ◮ Create tables ◮ Fill information into tables ◮ Select information (can sometime be very tricky) ◮ Update information

PHP MyAdmin

◮ A PHP program for managing MySQL BD’s ◮ Graphical and practical ◮ Do not require to log on the machine (only web access)

PHP Library for MySQL

◮ The old function-oriented library ◮ The new object-oriented library

PHP and MySQL Introduction 3

slide-4
SLIDE 4

MySQL a Data Base for the Web

Open-Source DB

◮ Free ◮ Present in any Linux distribution ◮ Available for fast any OS (Windows, Free-BSD, Mac-OS X,...)

The perfect solution for web

◮ LAMP architecture (Linux, Apache, MySQL, PHP) is one of

the web standards

◮ An application (phpMyAdmin) for managing the DB without

shell access

◮ Perfect integration within PHP.

PHP and MySQL Introduction 4

slide-5
SLIDE 5

Basics of MySQL commands

Creation functions (often done within PHP-MyAdmin)

◮ Create a new table ◮ Set the properties of fields (auto-increment, default value,...)

Routine functions (will be used in your programs)

◮ Insert an element in a table ◮ Select elements out of a table ◮ Select elements out of many tables ◮ Change the content of a record ◮ Delete some records

PHP and MySQL Basics of MySQL 5

slide-6
SLIDE 6

Creation of a table

Syntax

◮ CREATE TABLE table name (definition of the fields)

Create a small table CREATE TABLE ‘category‘ ( ‘name‘ VARCHAR( 100 ) NOT NULL , ‘categoryID‘ TINYINT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( ‘categoryID‘ ) );

◮ Create a table with two fields ◮ a string which length can not exceed 100 ◮ A primary key that is a counter

PHP and MySQL Basics of MySQL: Create a Table 6

slide-7
SLIDE 7

Create a new table

The table can have fields of the following types:

◮ TINYINT SMALLINT MEDIUMINT INT BIGINT that are integers

(more or less long)

◮ VARCHAR for short strings (smaller than 256 chars) ◮ TEXT for texts with a fixed length (max 64 kB) ◮ DATE date in format YYYY-MM-DD ◮ TIMESTAMP contains a unix timestamp ◮ TIME format hh:mm:ss ◮ DECIMAL number with a point. ◮ FLOAT ◮ DOUBLE real numbers ◮ BLOB Any Binary data (image, sound, long text, . . . ) ◮ . . .

PHP and MySQL Basics of MySQL: Create a Table 7

slide-8
SLIDE 8

Create a new table (Cont.)

Other attributes or features

◮ NULL or NOT NULL ◮ AUTO INCREMENT for counters

The table has also properties

◮ PRIMARY KEY ◮ COMMENT description of the table

PHP and MySQL Basics of MySQL: Create a Table 8

slide-9
SLIDE 9

Create other tables

The article and vat tables CREATE TABLE ‘article‘ ( ‘articleID‘ INT NOT NULL AUTO_INCREMENT , ‘name‘ VARCHAR( 100 ) NOT NULL , ‘vatID‘ TINYINT NOT NULL , ‘categoryID‘ INT NOT NULL , ‘Price‘ DECIMAL NOT NULL , PRIMARY KEY ( ‘articleID‘ ) ); CREATE TABLE ‘vat‘ ( ‘vatID‘ TINYINT NOT NULL AUTO_INCREMENT , ‘rate‘ DECIMAL NOT NULL , PRIMARY KEY ( ‘vatID‘ ) ) COMMENT = ’The table containing VAT rates’;

PHP and MySQL Basics of MySQL: Create a Table 9

slide-10
SLIDE 10

See the content of a data base

See all tables mysql> show tables; +-------------------+ | Tables_in_example | +-------------------+ | article | | category | | vat | +-------------------+ 3 rows in set (0.00 sec)

PHP and MySQL Basics of MySQL: See the content of a DB 10

slide-11
SLIDE 11

See the content of a data base (Cont.)

See all columns of a table

mysql> show columns from vat; +-------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra +-------+---------------+------+-----+---------+----------------+ | vatID | tinyint(4) | | PRI | NULL | auto_increment | rate | decimal(10,2) | | | 0.00 | +-------+---------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)

PHP and MySQL Basics of MySQL: See the content of a DB 11

slide-12
SLIDE 12

Change a Table - ALTER

Remove columns ALTER TABLE t2 DROP COLUMN c, DROP COLUMN d; Add a new column ALTER TABLE ‘article‘ ADD ‘description‘ BLOB NOT NULL ; Change an existing column ALTER TABLE ‘article‘ CHANGE ‘Price‘ ‘price‘ DECIMAL( 10, 2 ) DEFAULT ’0’ NOT NULL;

PHP and MySQL Basics of MySQL: Tables: Change rows and Insert data 12

slide-13
SLIDE 13

Fill data into a table - INSERT

Syntax

◮ INSERT INTO tablename [(list of fields)] VALUES (list of

values);

◮ all not null fields must be set, other can be just two

commas. Insert a row in a table INSERT INTO ‘article‘ ( ‘articleID‘ , ‘name‘ , ‘vatID‘ , ‘categoryID‘ , ‘price‘ , ‘description‘ ) VALUES (’’, ’Pencil’, ’0’, ’0’, ’1.50’, ’’); Other possibility INSERT INTO article values (’’,’Mercedes Class E’,’0’,’0’,’100000’, ’The same Mercedes Lady Diana has used’ );

PHP and MySQL Basics of MySQL: Tables: Change rows and Insert data 13

slide-14
SLIDE 14

Change the content of one or many rows

UPDATE a table UPDATE ‘article‘ SET ‘description‘ = ’A very nice black pencil with white stripes’ WHERE ‘articleID‘ = ’1’ LIMIT 1 ;

PHP and MySQL Basics of MySQL: Tables: Change rows and Insert data 14

slide-15
SLIDE 15

Select information

Syntax

◮ SELECT Field list FROM list of tables [WHERE conditions]

[LIMIT limits]

◮ Field list can also be a joker (*) ◮ Conditions can be combined with boolean connectors (AND,

OR, NOT)

◮ If we only want to see a part of a list, we can limit it.

Select all the rows and columns of a table mysql> select * from vat; +-------+------+ | vatID | rate | +-------+------+ | 1 | 7.00 | | 2 | 7.65 | +-------+------+

PHP and MySQL Basics of MySQL: Select Information 15

slide-16
SLIDE 16

Select information(Cont.)

Select only some columns mysql> select name, price from article; +------------------+-----------+ | name | price | +------------------+-----------+ | Pencil | 1.70 | | Mercedes Class E | 100000.00 | +------------------+-----------+ 2 rows in set (0.00 sec)

PHP and MySQL Basics of MySQL: Select Information 16

slide-17
SLIDE 17

Select data

Select only some rows mysql> select name, price from article

  • > where articleID=1;

+--------+-------+ | name | price | +--------+-------+ | Pencil | 1.70 | +--------+-------+ 1 row in set (0.01 sec)

PHP and MySQL Basics of MySQL: Select Information 17

slide-18
SLIDE 18

Merge data from different tables

Merge two tables

◮ Fields must know from which table they come (the same field

can be in the two tables).

◮ We can rename a requested field with the AS keyword.

mysql> select article.name, vat.rate, article.price

  • > from article, vat where article.vatID= vat.vatID;

+------------------+------+-----------+ | name | rate | price | +------------------+------+-----------+ | Pencil | 7.00 | 1.70 | | Mercedes Class E | 7.00 | 100000.00 | +------------------+------+-----------+

PHP and MySQL Basics of MySQL: Select Information 18

slide-19
SLIDE 19

Merge ...(Cont.)

Merge and compute mysql> select article.name, vat.rate, article.price,

  • > article.price*(1+vat.rate/100) as priceWithVAT
  • > from article, vat where article.vatID= vat.vatID;

+------------------+------+-----------+--------------+ | name | rate | price | priceWithVAT | +------------------+------+-----------+--------------+ | Pencil | 7.00 | 1.70 | 1.8190 | | Mercedes Class E | 7.00 | 100000.00 | 107000.0000 | +------------------+------+-----------+--------------+ 2 rows in set (0.00 sec)

PHP and MySQL Basics of MySQL: Select Information 19

slide-20
SLIDE 20

Join

INNER JOIN If there is no match, the second table is replaced by an empty record. select article.name, vat.rate, article.price from article inner join vat

  • n article.vatID= vat.vatID;

LEFT JOIN If there is no match, the second table is replaced by an empty record. select article.name from article left join vat

  • n article.vatID= vat.vatID

where vat.rate is null; (gives the list of articles with undefined VAT)

PHP and MySQL Basics of MySQL: Select Information 20

slide-21
SLIDE 21

More on SELECT

Result of a select can be put into a temporary table create temporary table valueVAT (select vat.rate, article.name from vat,article where vat.vatID=article.vatID ) ; You can access to the content and then delete this table select * from valueVAT; drop table IF EXISTS valueVAT;

PHP and MySQL Basics of MySQL: Select Information 21

slide-22
SLIDE 22

Select and more options

Order result (DESC or ASC) select name, price from article order by price desc; Group rows mysql> select vatID, count(vatID) > from article GROUP BY vatID; +-------+--------------+ | vatID | count(vatID) | +-------+--------------+ | 1 | 2 | +-------+--------------+ 1 row in set (0.00 sec) SELECT can have a lot of functions an combine all of them

PHP and MySQL Basics of MySQL: Select Information 22

slide-23
SLIDE 23

Delete fields

Delete the content of a table respectively to a where clause delete from article where articleID=3;

PHP and MySQL Basics of MySQL: Select Information 23

slide-24
SLIDE 24

Administrate MySQL with a Web interface

phpMyAdmin

◮ A PHP program for managing MySQL Data Bases ◮ Free available at http://www.phpmyadmin.net ◮ Included in most of the Linux distrib ◮ Internationalization

Management made easy Generate and displays the SQL query corresponding.

◮ Create a new Data Base ◮ Create a new Table ◮ Add or remove a column in a table

PHP and MySQL PhpMyAdmin 24

slide-25
SLIDE 25

phpMyAdmin

Management of data

◮ Select data made easy ◮ Update using a visual interface (does not work for BLOBs) ◮ A lot of selection boxes containing all the possible values

Import / Export of data

◮ Can create SQL Dump ◮ Can export in a lot of formats: SQL, CSV, LaTeX, CSV for

excel, XML

◮ With a lot of properties (zipped, gzipped, with delete tables or

not, . . . )

PHP and MySQL PhpMyAdmin 25

slide-26
SLIDE 26

Conclusion - MySQL/phpMyAdmin

Not as much powerful as other DB’s

◮ MySQL does not implement all of SQL ◮ It is enough to handle a small web site ◮ Very useful and easy to install, configure and manage

PHP supports all other DB’s

◮ Oracle ◮ ODBC (MS-SQL server, Access) ◮ Postgess ◮ DBase ◮ . . .

PHP and MySQL PhpMyAdmin 26

slide-27
SLIDE 27

PHP and MySQL

Three Libraries

◮ mysql old library ◮ mysqli new library ◮ pearDB multi-database library

mysql

◮ Used from the beginning of the language ◮ Compatible with a lot of existing code

mysqli

◮ New since php5 ◮ Contains objects and encapsulation

pear DB

◮ Compatible with almost any Data Base ◮ Syntax is the same and is platform independent ◮ Not as optimized as the two dedicated routines

PHP and MySQL PHP and MySQL together 27

slide-28
SLIDE 28

mysql : Connection to the Data Base

<?php $db = @mysql connect(’localhost’,’root’,’toto14’); if ($db) { echo ”Connection OK <br>\n”; echo ”Handle ID= $db\n”; } else{ echo ”Connection could not be established<br>”; echo mysql error(); } mysql close(); ?>

PHP and MySQL PHP and MySQL together: mysql 28

slide-29
SLIDE 29

Connection to a DB

Establish the connection $db = @mysql connect(’localhost’,’root’,’toto14’); Handle

◮ Returned by the connection ◮ One can play with more than one connection (multi-server) ◮ Is a number

Error handling echo mysql error(); Disconnect from the DB mysql close();

PHP and MySQL PHP and MySQL together: mysql 29

slide-30
SLIDE 30

Connexion script

<?php $host=’localhost’; $user=’root’; $pwd=’toto14’; $dbase=’example’; $conn = @mysql connect($server,$user,$pwd); /∗ // A persistant connection should be established if the server // should open a lot of connexions (which costs lot of time). $conn = @mysql pconnect($server,$user,$pass); ∗/ if($conn){ mysql select db($dbase, $conn); } else{ die(”The connection could not be established”); } ?>

PHP and MySQL PHP and MySQL together: mysql 30

slide-31
SLIDE 31

Persistent Connexion

Connexion requires a lot of time

◮ Establish TCP/IP connexion ◮ Exchange username password

Solution: share one persistent connexion $conn = @mysql connect($server,$user,$pwd); // will be replaced by $conn = @mysql pconnect($server,$user,$pass);

◮ The connection is not broken by mysql close() ◮ It is reused if the parameters are the same

PHP and MySQL PHP and MySQL together: mysql 31

slide-32
SLIDE 32

Execute Queries

execute a SQL query: mysql query(sql,conn) SQL queries are stored in an array and executed require(”connDB.php”); $querys= array(); $querys[]=”insert into article values(0,’Milk’,1,1,”. ”’10.90’,’Super milk for the kids’);”; $querys[]=”insert into article values(0,’Cafe’,1,”. ”1,’10.90’,’Super cafe for the adults’);”; foreach($querys as $query){ mysql query($query , $conn); } mysql close($conn);

PHP and MySQL PHP and MySQL together: mysql 32

slide-33
SLIDE 33

Select data

Count the number of selected rows $query = ”select ∗ from article”; $result = mysql query($query , $conn); if($result){ $nbRows = mysql num rows($result); echo ”$nbRows have been selected <br>”; } else{ die(mysql error()); }

PHP and MySQL PHP and MySQL together: mysql 33

slide-34
SLIDE 34

Select data (Cont.)

Error handling

◮ Handler $result is 0 when an error occurs ◮ Call function mysql error() to access to the error;

PHP and MySQL PHP and MySQL together: mysql 34

slide-35
SLIDE 35

Fetch result of a select

require once(”connDB.php”); $query = ”select ∗ from article”; $result = mysql query($query , $conn); if($result){ $nbRows = mysql num rows($result); echo ”$nbRows have been selected by query:<br>$query <br>\n”; // arrayType can be : MYSQL ASSOC, MYSQL NUM, MYSQL BOTH while( $row = mysql fetch array($result, MYSQL ASSOC)){ echo implode(”,”,$row).”<br>\n”; } } else{ echo mysql error(); } mysql close($conn);

PHP and MySQL PHP and MySQL together: mysql 35

slide-36
SLIDE 36

Fetch result of a select (Cont.)

Types of arrays

◮ MYSQL ASSOC keys are field names ◮ MYSQL NUM keys are numbers ◮ MYSQL BOTH keys are both numbers and field names

fetch a single row until no more is accessible while( $row = mysql fetch array($result, MYSQL ASSOC))

PHP and MySQL PHP and MySQL together: mysql 36

slide-37
SLIDE 37

Fetch a row into an object

Creates an object whose member variables are fields if($result){ $nbRows = mysql num rows($result); echo ”$nbRows have been selected by query:<br>$query <br>\n”; while( $obj = mysql fetch object($result)){ echo ”{$obj−>name}, => CHF {$obj−>price} <br>\n”; } }

PHP and MySQL PHP and MySQL together: mysql 37

slide-38
SLIDE 38

Insert data into a table

$query = ”insert into article values(0,’Milk UHT’, ”. ”1,1,’7.90’,’Super milk for kids’)”; $result= mysql query($query , $conn); if(!$result){ echo mysql error; } $newID = mysql insert id(); $query2 = ”update article set price=’5.5’”. ” where articleID=$newID”; $result2= mysql query($query2 , $conn); if(!$result2){ die(”Could not execute $query2 ”.mysql error()); } $affectedRows = mysql affected rows($conn); echo ”number of affected rows:$affectedRows<br>\n”;

PHP and MySQL PHP and MySQL together: mysql 38

slide-39
SLIDE 39

Insert and Update

Insert

◮ Create a new record in the table ◮ ID automatically generated (with auto increment) ◮ We need to access this counter: ◮ $newID = mysql insert id();

Update

◮ Useful to change the tables ◮ Programmer want to know if it worked ◮ Indication: the number of affected rows: ◮ mysql affected rows($conn)

PHP and MySQL PHP and MySQL together: mysql 39

slide-40
SLIDE 40

Manipulate the Data Base itself

require once(”connDB.php”); $res = mysql list dbs($conn); for($i=0;$i < mysql num rows($res);$i++){ $dataBase= mysql tablename($res,$i); $result=0; $query = ”show tables from $dataBase”; $result = mysql query($query , $conn); if($result){ $nbTables = mysql num rows($result); echo ”<b>$dataBase</b>has $nbTables tables <br>\n”; while( $row = mysql fetch array($result, MYSQL ASSOC)){ echo implode(”,”,$row).”<br>\n”; } } } mysql close($conn);

PHP and MySQL PHP and MySQL together: mysql 40

slide-41
SLIDE 41

Manipulate Data Base (Cont.)

View all present Data Bases $res = mysql list dbs($conn); ... for($i=0;$i < mysql num rows($res);$i++){ $dataBase= mysql tablename($res,$i); View the content of a data base ”show tables from $dataBase”

PHP and MySQL PHP and MySQL together: mysql 41

slide-42
SLIDE 42

mysqli an improved library

Available since version MySQL 4.1

◮ Object oriented syntax; ◮ more efficient to access the DB; ◮ functionalities are the same

Example $host=’localhost’; $user=’root’; $pwd=’toto14’; $dbase=’example’; $mi = new mysqli($host,$user,$pwd,$dbase); if(mysqli connect errno()!=0){ Die (”Connection aborted”.mysqli connect error()); } echo $mi−>stat(); $mi−>close();

PHP and MySQL PHP and MySQL together: mysqli 42

slide-43
SLIDE 43

Select with mysqli

$host=’localhost’; $user=’root’; $pwd=’toto14’; $dbase=’example’; $mi = new mysqli($host,$user,$pwd,$dbase); if(mysqli connect errno()!=0){ Die (”Connection aborted”.mysqli connect error()); } $sql = ’select ∗ from article’; $result = $mi−>query($sql); if(is object($result)){ $number = $result−>num rows; echo ”Number of rows: $number<br>\n”; while ($row = $result−>fetch array(MYSQLI ASSOC)){ echo implode(”, ”, $row); } } else{ Die($mi−>error); } $mi−>close();

PHP and MySQL PHP and MySQL together: mysqli 43

slide-44
SLIDE 44

Pear DB library

Standard library for handling data bases data base (pear prefix)

◮ dBase (dbase) ◮ FrontBase (fbsql) ◮ InterBase (ibase) ◮ Informix (ifx) ◮ MiniSQL (msql) ◮ Microsoft SQL Server (mssql) ◮ Mysql (mysql) ◮ Mysqli (mysqli) ◮ Oracle, version 7, 8 and 9 (oci8) ◮ PostgreSQL (pgsql) ◮ SQLite (sqlite) ◮ Sybase (sybase)

PHP and MySQL PHP and MySQL together: Pear DB Library 44

slide-45
SLIDE 45

Pear DB library(Cont.)

Platform independent

◮ Development does not depend too much of the server ◮ Should be possible to replace a server by another one just

changing the connexion.

PHP and MySQL PHP and MySQL together: Pear DB Library 45

slide-46
SLIDE 46

Basics of the language

Connexion to the DB $db=DB::connect(’mysql://root:toto14@localhost/example’); String = server type:// user : password @ server / database Connexion Error Handling if(DB::isError($db)){ Die(”Error ”.$db−>getMessage().”<br>\n”); } Uses a static method for DB class to test if $db is an error. Insert into a table $query = ”insert into vat values(’’,19.6)”; $q = $db−>query($query); if (DB::isError($q)){ Die(”query error :”.$q−>getMessage()); }

PHP and MySQL PHP and MySQL together: Pear DB Library 46

slide-47
SLIDE 47

Example

require ’DB.php’; $db=DB::connect(’mysql://root:toto14@localhost/example’); if(DB::isError($db)){ Die(”Error ”.$db−>getMessage().”<br>\n”); } $query = ”insert into vat values(’’,19.6)”; $q = $db−>query($query); echo ”execute <code>$query</code><br>\n”; if (DB::isError($q)){ Die(”query error :”.$q−>getMessage()); } /∗ //equals $db−>setErrorHandling(PEAR ERROR DIE); $q = $db−>query($query); ∗/

PHP and MySQL PHP and MySQL together: Pear DB Library 47

slide-48
SLIDE 48

Queries using place holders

// We can use a placeholder in a query : ? $db−>setErrorHandling(PEAR ERROR DIE); $query = ”insert into vat values(’’,?)”; $val1 = 20.6; $db−>query($query, $val1); // We can also use many placeholders $query = ”insert into article values(’’,?,1,1,?,?)”; $name = ’Computer’; $price=1500; $description=’This computer is tip−top, very cheap and fast’; $price <br>\$description = $description<br>\n”; $db−>query($query, array($name,$price,$description));

PHP and MySQL PHP and MySQL together: Pear DB Library 48

slide-49
SLIDE 49

Display result of a query

Get all results in an array Each row is an numeric array $query = ’select ∗ from article where price < 100’; $q = $db−>query($query); echo ”Query <code>$query</code> selected”. ” {$q−>numrows()} rows<br>\n”; $rows = $db−>getAll($query); foreach($rows as $row){ foreach($row as $value){ echo ”$value, ”; } echo ”<br>\n”; }

PHP and MySQL PHP and MySQL together: Pear DB Library 49

slide-50
SLIDE 50

Display result of a query (Cont.)

Display only one row $queryCheapest=”select name,price ”. ”from article order by price ”. ”limit 1”; $cheapest = $db−>getRow($queryCheapest); echo ”The cheapest article is {$cheapest[0]}”. ” at {$cheapest[1]}<br>\n”; Display only one value $queryCheapest=”select name,price ”. ”from article order by price ”. ”limit 1”; $cheapest = $db−>getOne($queryCheapest); echo ”The cheapest article is {$cheapest}<br>\n”;

PHP and MySQL PHP and MySQL together: Pear DB Library 50

slide-51
SLIDE 51

Assoc fetchmode

Each row is put in an associative array $db−>setFetchMode(DB FETCHMODE ASSOC); $query = ”select ∗ from article”; $res = $db−> query($query); while($row = $res−>fetchRow()){ echo ”The price of $row[name] is $row[price]<br>\n”; } $rows = $db−>getAll($query); foreach($rows as $row){ echo ”{$row[’name’]} at CHF {$row[’price’]}<br>\n”; } $expensive = $db−>getRow(”select ∗ from article ”. ”order by price desc limit 1”); echo ”The most expensive article is $expensive[name]”. ” at CHF $expensive[price]<br>\n”;

PHP and MySQL PHP and MySQL together: Pear DB Library 51

slide-52
SLIDE 52

Fetch-mode object

Each row is mapped inside an object $db−>setFetchMode(DB FETCHMODE OBJECT); $query = ”select ∗ from article”; $res = $db−> query($query); while($row = $res−>fetchRow()){ echo ”The price of $row−>name is $row−>price<br>\n”; } $rows = $db−>getAll($query); foreach($rows as $row){ echo ”{$row−>name} at CHF {$row−>price}<br>\n”; } $exp= $db−>getRow(”select ∗ from article order by price desc limit 1”); echo ”$exp−>name at CHF $exp−>price<br>\n”;

PHP and MySQL PHP and MySQL together: Pear DB Library 52

slide-53
SLIDE 53

Conclusion Data Base

DB are the center of our work

◮ Do not require a programmer to write HTML ◮ they are used to access DB’s ◮ forms and db’s are the two pillars of web programming ◮ a lot of other finesses to be discovered ◮ SQL : a semester course of 2 hours a week

PHP supports all data bases

◮ A standard web architecture is LAMP: Linux Apache MySQL

PHP

PHP and MySQL Conclusion 53