#3, Май'2004 :: Спецвыпуск. PHPConf 2004

  • Published on
    23-Feb-2016

  • View
    222

  • Download
    0

Embed Size (px)

DESCRIPTION

Smarty - MySQL PHP: XML- - PostgreSQL? PEAR - I. . Object-Relational Mapping

Transcript

  • 5 !

    MySQL (. 12)

    PostgreSQL? (. 33)

    PHP: (. 17)

    -

    3 '04

    2004

  • PHP Inside 3

    ( )....................................................................................................1Smarty - ( )................................................................... 3 MySQL ( )....................................................12 PHP: , ( )............................................................. 17 XML- - ( )....................25 PostgreSQL? ( )........................................................................................... 33 PEAR - ( )...............42 I. ( )........................................................................................ 50 .................................................................................................................... 62

    -

    - - PHP, 14 . PHP(http://www.phpclub.ru) (http://www.3planeta.ru) - , -. - .

    , , - . http://phpclub.ru/talk , , - . .

    , , , - .

    [Yamert], . , , [PHPClub], , - ( - ).

    [Sad Spirit], , : PEAR PostgreSQL. - , - : -, - .

    [Demiurg], - . Smarty , , -. : - .

    1

    :

  • PHP Inside 3

    [], . , , MySQL , MySQL.

    [fisher] - , - , .

    [DAN], , , - XML-.

    - , , -, .

    , , , . - ? .

    , , .

    - . , . , , , , - .

    - , ., , (http://phpclub.ru) (http://www.3planeta.ru).

    2

    .

  • PHP Inside 3 Smarty -

    Smarty -

    , PHP , HTML. , , PHP, PHP- HTML. , , , html (, , ). -. -, . . - PHP- HTML. - .

    , . HTML ( ), - . PHP- HTML , , , , - HTML.

    -

    , Model/View/Controller (MVC). MVC (Model), (View) -(Controller). , -, . , - , . , - . - markup language ( ). controller, , -. PHP.

    MVC WEB, , ,

    . PHP- (Controller). , (Model), (View), , -. , .

    3

    :

  • PHP Inside 3 Smarty -

    . 2. -

    , ( ). , -. , , - .

    Smarty VS Others

    Smarty. , Smarty - - , HTML . Smarty Sigma PEAR.

    4

    . 1. MVC

  • PHP Inside 3 Smarty -

    Sigma.

    :

    :

    Smarty.

    :

    5

    {first_name} {last_name}

  • PHP Inside 3 Smarty -

    :

    , Smarty , . , Smartyc Smarty , . Sigma , , HTML-- . , Smarty , Sigma .

    . , . - . - . , , , , , , , . . Smarty , , - , .

    , -. , , , -, - . Smarty, , - . , , - , , , - , . , , .

    , Smarty Smarty. Smarty -

    , .

    Smarty (compiling PHP template engine). , , , PHP-.

    - , . , , - , . , .

    6

    {foreach name=outer item=contact from=$contacts} {foreach key=key item=item from=$contact} {$key}: {$item} {/foreach}{/foreach}

  • PHP Inside 3 Smarty -

    -, . ,, PHP-, , - , .

    , , Smarty -

    , , , , . , -. , Smarty , -, . - section. :

    :

    , Smarty :

    foreach , . - : sectionelse foreachelse, - , .

    :

    , , , , ..

    (if). ,

    - php.

    7

    {section name=customer loop=$custid} id: {$custid[customer]} {/section}

    id: 1000id: 1001id: 1002

    {_ 1=1 2=2 ...}_

    {/_ }

    {_ 1=1 2=2 ...}

    {section name=customer loop=$custid} id: {$custid[customer]}{sectionelse} there are no values in $custid.{/section}

  • PHP Inside 3 Smarty -

    :

    ,

    :

    C , Smarty , -.

    Smarty

    . Smarty , . - function._.php php- smarty_function__($params, &$smarty), . , , $params. :

    Smarty , -

    . , , , html, :

    8

    {if $name=="Fred" || $name=="Wilma"} ...{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}{elseif $var is even by 3} ...{else} ...{/if}

    {assign var="name" value="Bob"}

    function smarty_function_eightball($params, &$smarty){ $answers = array('Yes', 'No', 'No way', 'Outlook not so good', 'Ask again soon', 'Maybe in your reality'); $result = array_rand($answers); return $answers[$result];}

    {$str|escape:"html"}

  • PHP Inside 3 Smarty -

    :

    , , - . . modifier._.php PHP- smarty_modifier_ _ ($string). -:

    , -, , - PHP- . , - str_repeat:

    Smarty -

    . , , - . - :

    - config_load. , , . , - .

    - {#_#} {$smarty.config. _}.

    9

    {$str|escape:"html"|upper}

    function smarty_modifier_capitalize($string){ return ucwords($string);}

    {$str|str_repeat:3}

    # global variablespageTitle = "Main Menu"bodyBgColor = #000000tableBgColor = #000000rowBgColor = #00ff00[Customer]pageTitle = "Customer Info"[Login]pageTitle = "Login"focus = "username"Intro = """This is a value that spans more than one line. you must enclose it in triple quotes."""

  • PHP Inside 3 Smarty -

    , , Smarty -

    . , - , - , PHP, - , , , . , , - .

    , , Smarty (: Fatal error: Smarty:[in index.tpl line 28]: syntax error: missing section name in /path/to/smarty/Smarty.class.php on line 1041).

    , Smarty MVC . , MVC - , - , View-,, .

    , , Smarty - View- ( -). , , popup- . .

    Smarty , ,

    . , Smarty , , .

    : ? Smarty -, . , .

    , - . .

    , , -, .

    10

  • PHP Inside 3 Smarty -

    Smarty - cache_id, :

    Cache_id , . , . - , cache_id group|subgroup|id.

    , , , . , - .

    , Smarty -. , -, , (, )? .

    , Smarty insert. insert PHP-. , . , View Controller.

    , Smarty -

    - WEB-. HTML PHP- - , . , . Smarty , , Smarty -. http://smarty.php.net/

    11

    $smarty->caching = true;$my_cache_id = $_GET['article_id'];if(!$smarty->is_cached('index.tpl',$my_cache_id)) { // No cache available, do variable assignments here. $contents = get_database_contents(); $smarty->assign($contents);}$smarty->display('index.tpl',$my_cache_id);

  • PHP Inside 3 MySQL

    MySQL 4.1

    4.1 . :

    . 4.1. - , , , - Unicode (utf8 ucs2). ;

    GIS. MyISAM . OpenGIS. - :

    SRS (Spatial Reference System), , ;

    ;

    (prepared statements ). - MySQL - :

    ;

    ;

    4.1 . - , . , - ( 4.1), - MySQL :

    , :

    1. ;

    2. MySQL -old-passwords.

    GROUP_CONCAT(), ();

    12

    CREATE TABLE t1(l1 LINESTRING);INSERT INTO t1 VALUES(LineStringFromText('LINESTRING(0 0, 1 1, 2 2)'));

    Client does not support authentication protocol requestedby server; consider upgrading MySQL client

    :

  • PHP Inside 3 MySQL

    WITH ROLLUP, - GROUP BY. ROLLUP - . :

    ONDUPLICATE KEY UPDATE INSERT.

    INSERT .. ON DUPLICATE KEY UPDATE - - .

    TIMESTAMP DEFAULTCURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.

    DEFAULT CURRENT_TIMESTAMP TIMESTAMP , INSERT , ON UPDATE CURRENT_TIMESTAMP, - UPDATE.

    CREATE TABLE - :

    13

    mysql> SELECT country, year, SUM(profit) FROM t1 GROUP BY country, yearWITH ROLLUP;+----------+--------+----------------+| country | year | SUM(profit) |+----------+--------+----------------+| Albania | 2001 | 300 || Albania | 2002 | 100 || Albania | 2003 | 600 || Albania | NULL | 1000 || Denmark | 2001 | 800 || Denmark | 2002 | 1800 || Denmark | 2003 | 1600 || Denmark | NULL | 4200 || Greece | 2001 | 1500 || Greece | 2002 | 1100 || Greece | 2003 | 700 || Greece | NULL | 3300 || NULL | NULL | 8500 |+----------+---------+---------------+13 rows in set (0.00 sec)

    CREATE TABLE t1(dt timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,id int);CREATE TABLE t2(dt timestamp DEFAULT CURRENT_TIMESTAMP,id int);

  • PHP Inside 3 MySQL

    5.0 5.0 -

    . SQL-, . MySQL SQL:2003. DB2.

    :

    . ASENSITIVE,READ ONLY -SCROLL.

    5.0 (VIEW). (derived tables), - FROM, 4.1.

    5.0 VIEW, 5.1.

    : -

    MySQL (MySQL Core Certification) - MySQL (MySQL Professional Certification).

    . , - SQL, MySQL, - , MySQL AB, ..

    70 , 1,5 , .

    :

    http://www.mysql.com/training/certification/selftest/core/index.php

    , , - , -, , , MySQL. , - InnoDB, .

    70 , - 1,5 .

    14

    CREATE PROCEDURE proc1 (IN param1 INT,OUT param2 INT)BEGINSELECT SQRT(param1) INTO param2;END

    CREATE FUNCTION func1 (name CHAR(20)) RETURNS CHAR(50)RETURN CONCAT(name,' - kanistra!');

  • PHP Inside 3 MySQL

    - 135 .

    MySQL .

    MySQL GNU GPL .

    GPL MySQL -. , - . , , , MySQL, .

    , GPL, MySQL .

    MySQL GPL , - GPL .

    , - , , , - , :

    1. GNU GPL , - , - , ;

    2. , - - , ;

    3. MySQL , ;

    4. , , GPL - MySQL AB.

    - MySQL:

    /Academic Free License 2.0Apache Software License 1.0/1.1/2.0Apple Public Source License 2.0Artistic license Perl 5.8.0BSD license July 22 1999

    15

  • PHP Inside 3 MySQL

    /Common Public License 1.0GNU General Public License(GPL)

    2.0

    GNU Library "Lesser"General Public License(LGPL)

    2.1

    Jabber Open Source License 1.0MIT license -Mozilla Public License (MPL) 1.0/1.1PHP License 3.0Python license (CNRI PythonLicense)

    -

    Python Software FoundationLicense

    2.1.1

    Sleepycat License 1999W3C License 2001Zlib/libpng License -Zope Public License 2.0

    , -:

    - GPL , FreeSoftware Foundation OSI, GPL;

    - - GPL, - MySQL;

    , , licensing@mysql.com.

    , , . .

    - MySQL , .

    16

  • PHP Inside 3 PHP: ,

    PHP: , - -

    PHP?

    PHP, -, - . , - ; , , , . , - - PHP - - (), -.

    , , ,

    :

    1. . -, , - , ( - ), - - , - . , , . - () () , , (, LDAP), ;

    2. . -, , - , -. . , , , ;

    3. . , - , . , Logger ( ..). : FileLogger DBLogger , , - . ;

    , , PHP 4:

    1. public static. private protected ( PHP 5) , - , , - ;

    17

    :

  • PHP Inside 3 PHP: ,

    2. . - ( );

    3. , - $this->... .

    MVC:

    MVC (Model-View-Controller, --). - 3 , :

    1. . , ;

    2. , -;

    3. , - , . , - .

    3 - :

    1. ;

    2. ( -HTML, . WML, ..) - . ; - ;

    3. , .

    , .

    18

    . 1. .

  • PHP Inside 3 PHP: ,

    1 , - , :

    1. client ( ). product, ( order), ;

    2. product ( ), - . ( , &). - Supplier;

    3. product_category ;

    4. order , : , .;

    5. supplier , .

    ( MVC).

    2 , - , MVC-. (.. ).

    ShopModule ( Registry, ) . protected- log(), .

    name( ), log_engine ( - ( , PEAR::Log)), db_engine ( ), config (. ).

    19

    .2 .

  • PHP Inside 3 PHP: ,

    WebInterface . protected-handleGETRequest(), handlePOSTrequest() - . ( , - , - , HTTP- - ).

    , - (, CartInterface ) activate(). - , , , - . , , - CartInterface, activate().

    WebLogic . , - , (getProducts()), (buyProduct()) (getOrderStatus()).

    WebView . , - model. , tpl_engine (, PEAR::Sigma), - . - , printErrorForm(), - . WebView, ( PC, ., PDA). PC.

    20

    3. MVC .

  • PHP Inside 3 PHP: ,

    MVC, Registry(..4), - , ..

    , . - . ( ShopModule) . .

    (static), ( final).

    . .

    21

    . 4. .

    .5. -.

  • PHP Inside 3 PHP: ,

    , .1, .

    , ( ). , DBEntity :

    init() , , , - ;

    update(), delete(), insert() . SQL-;

    getTableName() ;

    getField() . ( - fields);

    setField() . .

    -, , init(), get- set-.

    , - ( , Client block() activate ()).

    .

    22

    .6. .

  • PHP Inside 3 PHP: ,

    PHP5 - PHP?

    , PHP5 . , ( ):

    1. (try/catch );

    2. private, protected, public;

    3. abstract, final;

    4. ;

    5. static- ( );

    6. .

    , : - , .

    PHP. , , , - , , ZE2.

    23

    .7. (2 ).

  • PHP Inside 3 PHP: ,

    :

    1. , - , (overloading) ;

    2. - ;

    3. , static, , $this, - , . -, ;

    4. , .

    , , PHP4 PHP5:

    1. empty;

    2. , __construct(), ;

    3. , .

    , -, , - PHP4 .

    PHP4 PHP5 PHP4 -

    :

    :

    ;

    try/catch - .

    PHP5 .

    24

  • PHP Inside 3 XML- -

    XML- -

    - , - XML (eXtensible Markup Language). - , - . - W3C, xml- - , . , xml--. xml-.

    XML PHP 4 XML PHP 3-

    PHP. xml-- php- -, , PHP. xml- - xml-:

    1. SAX (Simple API for XML) -;

    2. DOM (Document Object Model) .

    SAX- php- xml expat. -: .

    DOM- php-domxml libxml. .

    25

    . 1. XML PHP 4.

    :

  • PHP Inside 3 XML- -

    SAX- , (parsing) - . , - . , DOM- , . , SAX- , .

    , xml- php-. , domxml. - , php- xml. -, .

    XSLT PHP 4XSLT (XSL Transformations) xml-

    (eXtensible StylesheetLanguage).

    PHP 4 API : sablotron ( xslt) libxslt( domxml). API xml-.

    , API domxml xslt - , , PHP - . , domxml DOM - W3C.

    PHP - , , , , - - . - ,...