Χρήση της PHP και επικοινωνία με τη ys01/using_php.pdf · 14/11/2007...

download Χρήση της PHP και επικοινωνία με τη ys01/using_php.pdf · 14/11/2007 Σχεδίαση

of 42

  • date post

    14-Feb-2019
  • Category

    Documents

  • view

    214
  • download

    0

Embed Size (px)

Transcript of Χρήση της PHP και επικοινωνία με τη ys01/using_php.pdf · 14/11/2007...

PHP MySQL

- forky@di.uoa.gr

14/11/2007 2

PHP PHP command-line PHP MySQL PHP

14/11/2007 3

PHP5 Scripting

http://www.php.net/docs.php (MySQL, Oracle,

MS SQL Server, IBM DB2 ..)

http://www.php.net/docs.php

14/11/2007 4

PHP tags

C $

// /* .. */

14/11/2007 5

14/11/2007 6

command-line

PHP Command Line Interface (CLI) command-line

shell> {/usr/local/php/bin/}php test.php

$argc ( ) $argv[i] ( i)

tags parser

14/11/2007 7

Give as a parameter a word to print

14/11/2007 8

PHP MySQL

MySQL Improved Extension (mysqli)

MySQL 4.1.3

http://www.php.net/mysqli MySQL Server

$link = mysqli_connect('polynikes.di.uoa.gr', 'user', 'password', 'test');

mysqli_close($link);

http://www.php.net/mysqli

14/11/2007 9

test

14/11/2007 10

$result = mysqli_query($link, $query);

array $row = mysqli_fetch_row($result); echo $row[0],' ',$row[1];

$obj = mysqli_fetch_object($result); echo $obj->SONOMA,' ',$obj->SN;

14/11/2007 11

14/11/2007 12

()

(prepared statement) MySQL Server

$stmt = mysqli_prepare($link, "INSERT INTO S

VALUES (?,?,?,?)"); ? WHERE

VALUES() INSERT

14/11/2007 13

(I)

mysqli_stmt_bind_param($stmt, "ssds", $sn, $sonoma, $katast, $spoli);

: i (Integer), d (Double), s (String), b (Blob)

mysqli_stmt_execute($stmt);

, mysqli_stmt_affected_rows($stmt);

mysqli_stmt_close($stmt);

14/11/2007 14

14/11/2007 15

14/11/2007 16

(II)

mysqli_stmt_execute()

mysqli_stmt_bind_result($stmt, $sn, $sonoma,

$katast, $spoli);

mysqli_stmt_fetch($stmt);

14/11/2007 17

14/11/2007 18

14/11/2007 19

include()

php include 'connect.php';

include

( )

14/11/2007 20

test(connect.php)

14/11/2007 21

PHP HTML

(http://www.di.uoa.gr/~username/test.php) login server di mkdir public_html directory

public_html tutorial HTML

http://www.it.uom.gr/project/htmlman/pages/ HTML 4.01 Specification

http://www.w3.org/TR/html4/

http://www.it.uom.gr/project/htmlman/pages/http://www.w3.org/TR/html4/

14/11/2007 22

Test page

14/11/2007 23

...

14/11/2007 24

(I)

Print all suppliers

14/11/2007 25

(II)

mysqli_free_result($result);}mysqli_close($link);?>

14/11/2007 26

HTTP GET

URL php ?

name=value &

http://www.di.uoa.gr/~forky/print_supplier.php?sn=S1

(SELECT) (.. INSERT, UPDATE, ..)

PHP $_GET['param']

http://www.di.uoa.gr/~forky/print_supplier.php?sn=S1

14/11/2007 27

(I)

...

14/11/2007 28

(II)

if (mysqli_stmt_fetch($stmt)){ printf(" %s : : %s, : %s, : %s ", $sn, $sonoma, $katast, $spoli); } else { printf(" %s !", $sn); } mysqli_stmt_close($stmt);} mysqli_close($link);?>

14/11/2007 29

HTTP POST

...

(controls) : text, checkbox, password, hidden, submit, ...

PHP $_POST['param']

14/11/2007 30

Post supplier number

o

14/11/2007 31

(I)

...

14/11/2007 32

(II)

if (mysqli_stmt_fetch($stmt)){ printf(" %s : : %s, : %s, : %s ", $sn, $sonoma, $katast, $spoli); } else { printf(" %s !", $sn); } mysqli_stmt_close($stmt);} mysqli_close($link);?>

14/11/2007 33

(I) ...

14/11/2007 34

(II)

14/11/2007 35

(I) ...

14/11/2007 36

(II)echo

14/11/2007 37

(III)

} else { printf(" %s !", $sn); } mysqli_stmt_close($stmt);}mysqli_close($link);?>

14/11/2007 38

14/11/2007 39

()

...

/

14/11/2007 40

()

if ($result = mysqli_query($link, $query)) { $i=1; while ($obj = mysqli_fetch_object($result)) { printf ("%d%s",$i,$obj->SN,$obj->SONOMA); $i++; } mysqli_free_result($result);}mysqli_close($link);?>

14/11/2007 41

()

...

14/11/2007 42

(I)

mysqli_free_result($result);}mysqli_close($link);?>