Σημειώσεις php/MySQL

download Σημειώσεις php/MySQL

of 26

  • date post

    08-Feb-2017
  • Category

    Documents

  • view

    217
  • download

    1

Embed Size (px)

Transcript of Σημειώσεις php/MySQL

  • PHP/MySQL

    1 26

    HTML

    HTML PHP (PHP code mode) :

    1 2 3

    echo (" editors, FrontPage, "); 4

    (short) tags. short_tags(), short_open_tag configuration setting config PHP PHP --enable-short-tags option.

    tags ASP asp_tags configuration setting. ASP-style tags 3.0.4. C Perl - (;) tag (?>) -, :

    PHP C , Shell

    PHP Comments

  • PHP/MySQL

    2 26

    1 : // ( ) 2 : /* */ ( block ) 3 : # comments , /

    . (Variables) .

    $.

    =

    letter _(underscore). +,-,&,* : $today=Monday; //(, string) $total=1000; //(number)

    case-sensitive .. $total $Total .

    : $total=10; $total=100;

    , . php . . Variable Example

  • PHP/MySQL

    3 26

    PHP (runtime) PHP. , (cast) settype() . , . PHP Integer 8 Double 4.254 String Goodmorning Boolean true (true false) gettype() PHP . , gettype() , . gettype() .

  • PHP/MySQL

    4 26

    PHP settype() . settype(), , , . 3.14 ( double) . , , . settype() (cast) , .

  • PHP/MySQL

    5 26

    $holder=(string) $undecided; echo gettype($holder); echo " is $holder"; //integer $holder=(integer) $undecided; echo gettype($holder); echo " is $holder"; //double $holder=(double) $undecided; echo gettype($holder); echo " is $holder"; //boolean $holder=(boolean) $undecided; echo gettype($holder); echo " is $holder"; echo "original variable type: "; echo gettype($undecided); ?> =. : $name=George . + 7+3 10 - 7-3 4 * 7*3 21 / 7/3 2.333333333 % 7%3 1 (concatenation) . , . , "hello"." world" "hello world" .

  • PHP/MySQL

    6 26

    , PHP , . , . : $x=6; $x=$x+3; // x 9 : $x=6; $x+=3; // x 9 += $x+=3 $x=$x+3 -= $x-=3 $x=$x-3 *= $x*=3 $x=$x*3 /= $x/=3 $x=$x/3 %= $x%=3 $x=$x%3 .= $x.=test $x=$x.test 1. ; $this_is_a_value $___test___ $metritis $the counter $my-name $count $2test 2. ; $test_val=6.5466; settype($test_val, integer); echo $test_val; 3. ; echo gettype(8);

  • PHP/MySQL

    7 26

    scripts . script , . . scripts .

    if if , PHP. . if (expr) statement , expr Boolean . expr TRUE, PHP , FALSE - . a b $a $b: . , if . , statement group. , a is bigger than b $a $b, $a $b: If if , .

    else

    , . ' else. else if if FALSE. , a is bigger than b $a $b, a is NOT bigger than b :

  • PHP/MySQL

    8 26

    elseif elseif, , if else. ' else, if if FALSE. , else, elseif TRUE. , a is bigger than b, a equal to b or a is smaller than b:

    elseif if. elseif ( ) TRUE . PHP, 'else if' ( ) 'elseif' ( ). .

    elseif if elseif FALSE, elseif TRUE.

    == != -

    === > >= <

  • PHP/MySQL

    9 26

    || Or () true or Or () true xor Xor ( true, ) && And () true and And () true ! Not () true 1. . = 2 = 4. . 2. script . . 3. script . 4. script a, b, c. max, . 5. 1. 0.7, 2. 0.5, 3. 0.4, 4. 0.8. . script 3.

    6. , :

  • PHP/MySQL

    10 26

    800 3,5 . :

    . . . . "" "" .

    . .

    . . . 0 2000 "" "".

    switch switch . switch (expression) { case value1: statements; break; case value2: statements; break; default: statements; , case. break switch. , case. default, . ! break, case default. , . while while PHP. while () { } while true, . loop, , ( PHP loop ). , while

  • PHP/MySQL

    11 26

    FALSE , - . while while (): endwhile; dowhile dowhile while . while loops do..while loop ( ). do { while (); 1. script PHP lang fr, es, en, de, gr. (, , , , ). ! 2. while sript 7.

    3. :

  • PHP/MySQL

    12 26

    1. 1 2 3 4 5 6 7 8 9 10 2. 2 4 6 8 10 12 14 16 18 20 3. 3 6 9 12 15 18 21 24 27 30 4. 4 8 12 16 20 24 28 32 36 40 5. 5 10 15 20 25 30 35 40 45 50 6. 6 12 18 24 30 36 42 48 54 60 7. 7 14 21 28 35 42 49 56 63 70 8. 8 16 24 32 40 48 56 64 72 80 9. 9 18 27 36 45 54 63 72 81 90 10. 10 20 30 40 50 60 70 80 90 100 printf %4d ( 4 ) %d.

    4. script .

    5. . : Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu. 1-9 (*) . .

    : :

    Hello 2 you!.

    :

    Hotel Echo Lima Lima Oscar ** Yankee Oscar Uniform!

  • PHP/MySQL

    13 26

    for

    for loops loops PHP. for loop :

    for (expr1; expr2; expr3) statement

    (expr1) loop.

    , expr2 . TRUE, loop . FALSE, loop .

    , expr3.

    for (expr1; expr2; expr3) statement 1. script 2000 1-10 : 2000 . . 2. for.

  • PHP/MySQL

    14 26

    scripts - . HTML server. HTML PHP. HTML. Form.php Name: Address: Test.php Self.php

  • PHP/MySQL

    15 26

    $user=$_POST[USER]; $address=$_POST[ADDRESS]; if ($user){ echo "Welcome $user"; echo "Your address is:$address"; } ?>

  • PHP/MySQL

    16 26

    (Arrays) . . $name (, , ). . , . , (key) (value). , 0. , , . array(), , [ ].

    array() .

    [ ] ( ), .

    $cars = array("Toyota", "Mercedes", "BMW", "Ferrari", "Renault"); $cars[] = "Toyota"; $cars[] = "Mercedes"; $cars[] = "BMW"; $cars[] = "Ferrari"; $cars[] = "Renault"; $cars[0] = "Toyota"; $cars[1] = "Mercedes"; $cars[2] = "BMW"; $cars[3] = "Ferrari"; $cars[4] = "Renault"; 1. ('Perl', 'PHP', 'C','Java', 'Pascal', 'Cobol', 'Visual Basic') . 2. (8, 12, 21, 3, 15, 6, 7, 32, 9) . 3. 2. 4. 2 . 5. 8 . , .

  • PHP/MySQL

    17 26

    6. , N! , . 7. php script N! (1*2*3*4*5.*). . 8. ! browser HTML.

  • PHP/MySQL

    18 26

    date()

    string date ( string format [, int timestamp] )

    string format string, integer timestamp timestamp.

    timestamp Fri, 13 Dec 1901 20:45:54 GMT Tue, 19 Jan 2038 03:14:07 GMT. ( , , integer 32-bit). windows 01-01-1970 19-01-2038.

    timestamp string, strtotime(). , timestamps ( UNIX_TIMESTAMP MySQL).

    format string:

    a - "am" "pm" A - "AM" "PM" B - Swatch Internet time d - , 2 ("01" "31"). D - , 3 . .. "Fri" F - , . .. "January" g - , 12 ("1" "12"). G - , 24 ("0" "23"). h - , 12 ("01" "12"). H - , 24 ("00" "23"). i - ("00" "59"). I ( i) - "1" , "0". j - ("1" "31"). l ( 'L') - , . .. "Friday" L - boolean ("0" "1"). m - ("01" "12"). M - , 3 . .. "Jan" n - ("1" "12"). O - Greenwich time . .. "+0200" r - RFC 822; .g. "Thu, 21 Dec 2000 16:01:07 +0200"

    ( PHP 4.0.4) s - ("00" "59") S - , 2 ("st", "nd",

    "rd" "th"). t - ("28" "31"). T - ; .. "EST" "MDT" U - Unix Epoch (January 1 1970 00:00:00 GMT) w - , ("0" () to "6" ()). W - ISO-8601,

    ( PHP 4.1.0) Y - , 4 ; .. "1999"