64
5 лет с вами! Эффективное использование MySQL (стр. 12) Почему PostgreSQL? (стр. 33) ООП в PHP: применение и эволюция (стр. 17) электронный журнал для веб-разработчиков № 3 Май '04 2004 специальный выпуск специальный выпуск специальный выпуск

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

  • Upload
    vital-b

  • View
    246

  • Download
    0

Embed Size (px)

DESCRIPTION

Smarty - компилируемые шаблоны Эффективное использование MySQL ООП в PHP: применение и эволюция Эффективное использование XML-технологий в веб-проектах Почему PostgreSQL? Использование PEAR для ускорения разработки веб-приложений Приложение I. Листинг слайдов. Object-Relational Mapping

Citation preview

  • 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;

    , , [email protected].

    , , . .

    - 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 - , , , , - - . - , XML PHP, - PHP 5 .

    XML, XSLT XML- PHP 5

    PHP 5 XML - libxml2. - PHP :

    XML;

    DOM;

    SimpleXML;

    XmlReader;

    26

  • PHP Inside 3 XML- -

    XSL;

    SOAP.

    xml SAX . , PHP 4. - , API libxml2, expat.

    dom DOM - W3C, . - domxml PHP 4 . , - dom DOM.

    simplexml xml- PHP. simplexml - xml--.

    , , - , . ( foreach() ), - .

    simplexml XPath-. - DOM. - - (, ..). , .

    Xmlreader PHP PECL, - . -, SAX . .

    xsl API libxslt - xml-. , libxml2 XML PHP 5. libxslt - xslt-, API libexslt.

    xsl- - PHP . PHP- , xsl- php- - xslt-. .

    xml, - , :

    W3C;

    ;

    27

  • PHP Inside 3 XML- -

    XPath dom, simplexml, xslt;

    XPointer, XIncludes dom;

    (Schema), RelaxNG, DTD;

    xml-;

    DOM;

    PHP Streams.

    -.

    xincludes include () PHP. . , - - php, xincludes .

    PHP 5 -, . - :

    , - - , - xincludes (. 1 ).

    , , - .

    28

    class VariableStream { var $position; var $varname; function stream_open($path, $mode, $options, &$opened_path) { $url = parse_url($path); $this->varname = $url["host"]; $this->position = 0; return true; } function stream_read($count) { $ret = substr($GLOBALS[$this->varname], $this->position, $count); $this->position += strlen($ret); return $ret; } function stream_eof() { return $this->position >= strlen($GLOBALS[$this->varname]); } function url_stat() { return array(); }}

  • PHP Inside 3 XML- -

    PHP5 libxml2 -. - , DOM. :

    29

    stream_wrapper_register("var", "VariableStream");$GLOBALS["bar"] = "hello world"; $dom = new domdocument;$dom->load('xinclude.xml');$dom->xinclude();print $dom->saveXML();

    --- xinclude.xml ---

    --- output --

    hello world

    1.

    Class books extends domDocument { function __construct() { parent::__construct(); } function addBook($title, $author) { $titleElement = $this->createElement("title"); $titleElement->appendChild($this->createTextNode($title)); $authorElement = $this->createElement("author"); $authorElement->appendChild($this->createTextNode($author)); $bookElement = $this->createElement("book"); $bookElement->appendChild($titleElement); $bookElement->appendChild($authorElement); $this->documentElement->appendChild($bookElement); }}$dom = new books();$dom->load("books.xml");$dom->addBook("PHP de Luxe", "Richard Samar, Christian Stocker");print $dom->saveXML();

    --- utput --- PHP de Luxe Richard Samar, Christian Stocker

  • PHP Inside 3 XML- -

    , , domxml PHP 4, xml--.

    , xml--, PHP 5, . - , , PHP 5 , - xml- . PHP 5 - XML .

    XML- -

    , , XML - , . , , - XML - .

    . - () . - XML. , - . . - Jakarta Struts, xml-. PHP- phpMVC;

    . , , XML - - XML-. MVC. XML (model) (view). , XSL-, - . XML ( , , ). , , , - , . XML - , , , , , .

    30

  • PHP Inside 3 XML- -

    - xml-, XPath-, XSL--, DOM- . , , ,, , XML, -;

    -. XML . , SOAP, xml-. - -, XML Schema.

    Internet XML. XML - (MathML) (XML Signature). - (CommerceML, EbXML):

    XML - -

    . , - -. - ( ) - , , , .

    - , ,PEAR::HTML_QuickForm. HTML- - , . XForms, - W3C.

    XForms HTML-, - , HTML- . - XForms .XForms - , , , XML-.

    , , , . , XForms, : (data model), (view) (controller) , , .

    31

  • PHP Inside 3 XML- -

    XForms - , . XForms - . - , - .

    XForms , . XML- . XForms , .XForms- , - . , .

    XForms - , . , - , -. XForms - .

    XForms XForms, , - . , - XForms , , - .

    - , , XForms, - -. , - . .

    , XForms -, XForms Web-.

    XML -

    , - .

    XML- - () , .

    -, XForms, - .

    32

  • PHP Inside 3 PostgreSQL?

    PostgreSQL? ,

    PostgreSQL , - , .

    PostgreSQL PostgreSQL 1977 , Ingres, -

    1977 1985 . Relational Technologies / Ingres( Computer Associates), .

    POSTGRES ( Post Ingres) 1986 . : -, , , -. , -, 1989 . , 2 3. POSTGRES , POSTGRES . POSTGRES - Illustra, Informix, IBM.

    1993 , , , . POSTGRES 1994 4.2.

    1994 , , POSTGRES SQL ( PostQUEL). Postgres95 .

    1996 , Postgres95 , , , - PostgreSQL. 6.0, - SQL. 1 PostgreSQL, .

    1 , , . PostgreSQL , .

    33

    :

  • PHP Inside 3 PostgreSQL?

    ,

    PostgreSQL . , , (, , ), - . - (SteeringCommitee), , .

    PostgreSQL BSD, -, , PostgreSQL, . , , - PostgreSQL Windows, 7.5.

    , POSTGRES, , . PostgreSQL, , , - ; PostgreSQL PostGIS.

    ( -) PostgreSQL. Red Hat, Afilias ( .org .info), Fujitsu PostgreSQL / - . , PostgreSQL, 2, .

    PostgreSQL PostgreSQL

    . - .

    . , .

    . 6.5 ( 1999.06.09) - . , , , - .

    2 PostgreSQL : Great Bridge

    34

  • PHP Inside 3 PostgreSQL?

    - . 7.1 ( 2001.04.13) - (Write Ahead Log), - .

    . 6.3 (1998.03.01), FROM ( derivedtables) 7.1.

    . 7.0( 2000.05.08), - .

    . 6.4(1998.10.30), - . - , -, SQL (RULE).

    . 6.4 PL/PgSQL3. (TCL, Perl, Python), PL/Java PL/PHP, .

    . 6.2 ( 1997.10.02).

    Unicode. ( Unicode) 6.4. PostgreSQL - .

    , -

    . 4 postgresqlontrib( contrib/ ), . http://www.pgfoundry.org/, - 5 , - PostgreSQL, http://gborg.postgresql.org/.

    :

    ;

    contrib/rserv: - ;

    ERServer: -, , .org .info, BSD;

    3 PL/SQL Oracle.4 .5 GForge (http://www.gforge.org/) fork SourceForge,

    PostgreSQL.

    35

  • PHP Inside 3 PostgreSQL?

    Slony I6: , - ;

    : - contrib/tsearch2;

    : PostGIS(http://www.postgis.org/).

    ? :

    . , - - ;

    ( , );

    - ( - );

    , (,) .

    : MySQL 4.1.x 4.1.x MySQL -

    group_concat(), . PostgreSQL , , group_concat():

    6 .

    36

    --, CREATE FUNCTION sql_concat(text, text) RETURNS text AS SELECT $1 || $2; LANGUAGE sql WITH (ISSTRICT); -- , sql_concatCREATE AGGREGATE group_concat ( BASETYPE = text, SFUNC = sql_concat, STYPE = text );

  • PHP Inside 3 PostgreSQL?

    :

    , -, . .

    4.1.x MySQL timestamp, , . PostgreSQL : - ( ) , ( ). :

    : phpBB2 -

    : phpBB27. , - users ( - ), phpbb_users. - :

    1. . : , - phpBB2;

    7 PostgreSQL.

    37

    test=# select field from foobar;field--------foo bar(2 rows)test=# select group_concat(field) from foobar;group_concat-------- foobar(1 row)

    CREATE TABLE foo (... modified timestamp(0) with time zone DEFAULT now() NOT NULL ); -- CREATE FUNCTION foo_modified() RETURNS TRIGGERAS BEGIN NEW.modified := now(); RETURN NEW;END; LANGUAGE plpgsql;--, CREATE TRIGGER foo_modifiedBEFORE UPDATE ON foo FOR EACH ROWEXECUTE PROCEDURE foo_modified();

  • PHP Inside 3 PostgreSQL?

    2. phpbb_users. : ;

    3. phpBB2 users. , phpBB2 .

    , -:

    , . - :

    , - phpBB2 ( ) . - phpBB2 .

    PL/PHP

    PL/PHP ( ) PostgreSQL PHP. - : http://plphp.commandprompt.com/, - RC1.

    38

    DROP TABLE phpbb_users;-- , phpbb_users,-- usersCREATE TABLE phpbb_users_info ( ...);-- , -- phpbb_usersCREATE OR REPLACE VIEW phpbb_users ASSELECT ...FROM users u, phpbb_users_info uiWHERE u.user_id = ui.user_id;

    CREATE OR REPLACE RULE phpbb_users_insert ASON INSERT TO phpbb_users DO INSTEAD ( INSERT INTO users ...; INSERT INTO phpbb_users_info ...;);CREATE OR REPLACE RULE phpbb_users_update AS ON UPDATE TO phpbb_users DO INSTEAD ( UPDATE users SET ...; UPDATE phpbb_users_info SET ...;);CREATE OR REPLACE RULE phpbb_users_delete ASON DELETE TO phpbb_users DO INSTEAD (DELETE FROM users WHERE user_id = OLD.user_id;-- phpbb_users_info );

  • PHP Inside 3 PostgreSQL?

    PHP spi_exec_query(), - , - PL/PHP. , .

    , PL/PHP - : trusted untrusted. trusted , - ( PHP safe mode), untrusted , PHP.

    PL/PHP:

    :

    7.5: PostgreSQL Win32 PostgreSQL

    Windows :

    Cygwin, - Linux Windows;

    , .

    Windows - 7.4, , , . 7.5, : http://candle.pha.pa.us/main/writings/pgsql/project/win32.html.

    ( 7.5 ) PostgreSQL Windows, - .

    39

    CREATE TYPE __testphptype AS (field text);CREATE OR REPLACE FUNCTION phpsplit(text)RETURNS SETOF __testphptype AS $words = preg_split(/\\\\s+/, $args[0]); $ret = array(); for ($i = 0, $cnt = count($words); $i < $cnt; $i++) { $ret[$i][0] = $words[$i]; } return $ret; LANGUAGE plphp WITH (ISSTRICT);

    testphp=# select * from phpsplit(This is PL/PHP at work.);field----------This is PL/PHP at work. (5 rows)

  • PHP Inside 3 PostgreSQL?

    :

    1. gcc MinGW ( MinGW ). MinGW MSYS http://mingw.org/;

    2. (zlib, bison,flex), http://www63.tok2.com/home/bitwalk/download.html

    3. Perl. Windows, ActivePerl (http://activestate.com/);

    4. , , CVS- PostgreSQL, FTP (http://www.postgresql.org/mirrors-ftp.html) dev/;

    5. :

    ( ) , , C:\pgsql, PATH bin/ lib/, PGDATA, . -:

    (postmaster.exe).

    ( ) PostgreSQL servicemanager, PostgreSQL , -. http://www.unm.edu/~efesar/pgsvc/index.html.

    , -

    . , ( ) , .

    :

    Windows. Windows , - Windows. Unix- Cygwin ( - ) - PostgreSQL;

    40

    $ ./configure && make && make install

    > initdb L C:/pgsql/share

  • PHP Inside 3 PostgreSQL?

    , - steep learning curve. , PostgreSQL, - SQL . , , - ..

    ( SQLite), , PostgreSQL. (-, ), , .

    , PostgreSQL - ( ) . ( - ) -.

    :

    . , (, ). , , , .. - , - .

    , PostgreSQL. - , PostgreSQL:http://detail.phpclub.net/store/html/postgresql/.

    41

  • PHP Inside 3 PEAR -

    PEAR -

    : - ? -, , , -, .

    - In Defense of Not Invented Here Syndrome(http://joelonsoftware.com/articles/fog0000000007.html). : -, , , , , . , , , .

    , ( -- ) . - , , , , - . - , , .

    , : - ? : PEAR.

    PEAR PEAR PHP Extension and Application

    Repository ( PHP). :

    ;

    API;

    .

    PEAR, , -, , , Java. - (Framework) -.

    PEAR :

    ( ) PHP, ?

    : PEAR - .

    42

    :

  • PHP Inside 3 PEAR -

    :

    PEAR - : - ( - PHPDoc);

    -, PEAR - -;

    , , -. , , , ., , , , , , - .

    PEAR - . - , - . ( ), , ., , , , .

    PEAR PEAR -

    . , , http://pear.php.net, :

    - ;

    XML-RPC . , - pear ;

    :

    , , ;

    ;

    ;

    . PEAR, - DocBook, () , API - , - phpDocumentor .

    43

  • PHP Inside 3 PEAR -

    - : , - .. - PEPr (PEAR Proposals), - (RFC) PEAR. , PEAR, :

    pear-general PEAR, - ;

    Pear-dev PEAR;

    Pear-doc , PEAR .

    ,

    , - - -.

    , Mail, Mail_Mime Net_SMTP, , -, HTTP_Request HTTP, Auth, Date, Log, XML_Parser. HTML_TreeMenu( ) Pager ( ).

    HTML HTML_QuickForm, .

    HTML_QuickForm ,

    HTML :

    : , -, . - select, radio, checkbox;

    . , ID , intval();

    . email, , - , ;

    - ;

    - . - , .

    44

  • PHP Inside 3 PEAR -

    . , . - , HTML_QuickForm, -, 55000 .

    HTML_QuickForm 20 . -

    HTML, : , . ( HTML_QuickForm_element -);

    . - , ;

    . 10 , : HTML_QuickForm_Rule ( ), callback ;

    . , - HTML_QuickForm_Rul;

    , - HTML_QuickForm_Renderer, -. HTML, , . Smarty, IT[X]/Sigma,Flexy;

    .

    45

    . 1. QuickForm.

  • PHP Inside 3 PEAR -

    1 () HTML_QuickForm ( ).

    QuickForm

    : addElement(), addRule(), validate(), exportValues() display().

    , - , . PEAR - .

    HTML_QuickForm_ControllerHTML_QuickForm_Controller

    HTML_QuickForm, .

    PageController, - : , .

    46

    1

  • PHP Inside 3 PEAR -

    : - , , - Controller . Controller .

    - : wizard, ..

    2.

    HTML_QuickForm (. 2).

    , QuickForm_Controller : . - , -.

    47

    . 2: QuickForm_Controller

  • PHP Inside 3 PEAR -

    -

    , , .

    QuickForm, , XML. , . - ( QuickForm) - QuickForm Builder.

    - ( ), . , -: Wiki http://www.mamasam.com/qfbuilder , . , Wiki, pear-dev.

    48

    2

  • PHP Inside 3 PEAR -

    DB_DataObject_FormBuilder, ORM DB_DataObject. DB_DataObject, .

    XForms: QuickForm -, , XForms , QuickForm.

    : , .

    : - , , (Renderer). - -. , , , -. pear-dev , , wysiwyg htmlarea.

    49

  • PHP Inside 3 I.

    I. - - : ORM-, ,

    JAVA, Perl, PHP, Python;

    PHP;

    ;

    , ;

    ORM: , (Propel)

    ORM:

    50

    :

    JAVA: TopLink (Oracle),

    WebObjects (Apple),

    JDO,Hibernate,Torque,

    OJB,Castor,Cocobase, VBSF ...

    Python DbObj, SQLObject,db_row,

    Forget SQL, Middle Kit,

    Modelling OR Bridge,

    OR Membrane, PyD...

  • PHP Inside 3 I.

    CRUD: create, read, update, delete -:

    (M1) ,

    A {id, a1, ... aN }

    (M2) 1:m, 2 :

    A{ id, a1, ... aN}, B{id,id_A,b1,...bN}

    id_A -

    (M3) m:n, 3 : 2 () + 1 ()

    A{id, a1, ... aN}, B {id,b1,...,bN}, A_B{id_A,id_B,...},

    id_A, id_B -

    M1: , :READ/SELECT

    SQL-

    (lasy loading) - , LOB

    where:

    ( - )

    order by,

    bind ( )

    group by (having)

    CREATE/INSERT, UPDATE

    : defaults, triggered

    :

    (value quoting, )

    - (MySQL autoincrement, ,)

    ( , , etc)

    LOB- ( -)

    where( UPDATE): ( - , )

    51

    Perl Class::DBI, Alzabo,

    Tangram, SPOPS,

    DBIx::DBO2 ...

    PHP PEAR::DB_DataObject,

    Metastorage (MDB),

    Propel ...

  • PHP Inside 3 I.

    DELETE

    where:

    M2: , 1:m:A{ id, a1, ... aN}, B{id,id_A,b1,...bN}, id_A -

    (M1)

    A: B

    B:

    A B (lasy);

    e A 2 : SET NULL B

    :

    B: A

    B - A:

    Lasy: ;

    ;

    B (left outer join).

    B - A.

    M3: , m:n:A{id, a1, ... aN}, B {id,b1,...,bN}, A_B{id_A,id_B,...}

    (- - A, ):

    , (, pkeys, pkeys + -)

    (, )

    ()

    .

    ORM (PHP)--:

    : () . C , , , 1:m/m:n, CRUD- ( );

    52

  • PHP Inside 3 I.

    :

    :

    53

  • PHP Inside 3 I.

    : 1. ;

    2. - (, 1:m);

    3. - (, m:n);

    4. ( ).

    1: /

    54

    $schema = array (##############################'DOC' => array (##############################

    TITLE_NAME => 'TITLE',FIELDS => array(

    'ID'=>NUMBER,'TITLE'=>VARCHAR,'ANONS'=>VARCHAR,'BODY'=>CLOB,'AUTHOR'=>VARCHAR,'SRC'=>VARCHAR,'DATE_REC'=>DATE,'PRIORITY'=>NUMBER,'ID_STATUS'=>NUMBER,'DATE_EDIT'=>DATE,

    ),PRIMARY_KEY => 'ID',AUTO_INCREMENT => 'S_DOC',DATE_FORMATS=>array(

    'DATE_REC'=>'dd/mm/yyyy hh24:mi','DATE_EDIT'=>'dd/mm/yyyy hh24:mi',

    ),DONT_UPDATE => array('DATE_EDIT'=>1),NO_QUOTES => array('DATE_REC' => 1),DEFAULTS=>array(

    'STATUS'=>1,'PRIORITY'=>10,

    ),PREFERENCES => array (

    'STATUS' => 'ID_STATUS')

    ));

  • PHP Inside 3 I.

    2:

    55

    # $art_data = araay();# HTTP $sql_where = $art_controller->build_where($art->atts);$n_rows = $art->get_list($art_data,

    array(WHERE_CLAUSE=>$sql_where,ORDER_CLAUSE=> 'datetime desc')); # $arty->get_collction ( )# , /# action - DML: DELETE, UPDATE, INSERT ($id='new')if (1 == $art->db_action($params,$action) && is_null($db_manager->error)) {

    if ($db_manager->connit()) { # OK..} else {

    # , # "" ...$db_manager->rollback();

    }} else { #

    ...$db_manager->rollback();

    }

    # ###################################################function article(&$db_manager) {################################################### $this0>entity('DOC', $db_manager);};$db_manager = & new db_manager($conn,$owner,$schema);$art = & new article($db_manager);# if (1 != $art->select(array($art->pkeyname => $id)) {

    # document not found...

    }

    # :######################################'STATUS' => array (######################################

    TITLE_NAME => 'NAME',FIELDS => array(

    'ID'=>NUMBER,'NAME'=>VARCHAR,

    ),PRIMARY_KEY=>'ID',AUTO_INCREMENT=> 'S_STATUS'

    )# $status = & new status($db_manager);

  • PHP Inside 3 I.

    3: -

    56

    # (title)# 2 - ############################################################################function self_select (&$params) {############################################################################

    if(1 != parent::selfselect($params)) return NULL;if($this->id_status>0 && 1 != $this->status->select(array( $this->status->pkeyname => $this->id_status) )){ # ,

    ...}

    }

    # ... ,# $status->get_list();# : , # "" (NULL -)# :# - self_delete# - relation_m1_handler# - - store_handler# relation_m1_handler$this->docs_relation = & new relation_m1($this,$this->docs_entity,$this->db_manager);$this->add_store_handler (

    new relation_m1_handler('docs_relation',array(ON_DELETE=>SET_NULL))); #

    # #############################################################'BASKET' => array (#############################################################

    TITLE_NAME => 'NAME',FIELDS => array(

    'ID'=>NUMBER,'NAME'=>VARCHAR,

    ),PRIMARY_KEY => 'ID',AUTO_INCREMENT => 'S_BASKET'

    ),

  • PHP Inside 3 I.

    4:

    57

    #############################################################'BASKET_DOC' => array (#############################################################

    TYPE => RELATION,TITLE_NAME => 'NAME',FIELDS => array(

    'ID_BASKET'=>NUMBER,'ID_DOC'=>NUMBER,

    ),REFERENCES => array(

    'DOC' => 'ID_DOC','BASKET' => 'ID_BASKET'

    ))# basket:# # $this->docs_relation = & new relation_mm('DOC','BASKET_DOC',$db_manager);$this->add_store_handler(new relation_mm_handler('docs_relation'));

    # :$this->add_store_handler($new serarch_handler(

    array('TITLE'=>10,'BODY'=>5)));# include_once('search_engine.php');###########################################################class search_handler extends store_handler {###########################################################var $fields_weight; ####################################################### function search_handler ($fields_weight) { #######################################################

    parent::store_handler();$this->fields_weight = $fields_weight;

    } ####################################################### function before_delete(&$obj,&$params) { #######################################################

    if(1 != delete_object(...) )} ... # return NULL;}return 1;

    }

  • PHP Inside 3 I.

    ( , ,

    - )

    1. SQL ( , RAD)

    2. ( + )

    3. , -/

    4. -. -, . / .

    ORM (advanced feature list)

    Lasy loading -,

    , -

    ORMwww.c2.com/cgi/wiki?ObjectRelationalTollComparison (-

    )

    1. SQL-;

    2. ;

    3. ;

    4. GROUP BY, ;5. LASY LOADING;

    6. ( , );

    58

    # before_insert - before_update ####################################################### function before(&$obj,&$params) {

    ...if (0== $status) { if (1 != add_object(...)) {

    ..return NULL;

    } return 1;} else { if (1 != delete_object(...)) {

    ...return NULL;

    } return 1;}

  • PHP Inside 3 I.

    7. , ;

    8. 1:1, 1:m, m:n ;

    9. ;

    10. table-per-{hierarchy,concrete-class, subclass};

    11. OUTER JOIN;

    12./ (vesion numbers, timestamps,..);

    13. ;

    14. (-,, );

    15. - ;

    16. / -;

    17. ;

    18. - ;

    19. , ;

    20. SQL-.

    - m:n(): -

    , . - -,, , . - ( ).

    . -: (m:n, CollectionProxy), - (1:m,ReferenceProxy), ...

    ,

    (MyCollectionProxy,MyReferenceProxy, ...)

    Runtime SQL-building : SQL, , -

    ;

    4 : Criteria, OQL, named SQL, hand-coded. ;

    59

  • PHP Inside 3 I.

    SQL- , ;

    OQL(Hibernate - HQL): from a where a.b.b_attr = ...

    ,

    () ;

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

    (1): -,, ( , );

    : (, - ).

    -

    ORM. , OM (, ), - . :, ( );

    ORM (- );

    , ORM - ;

    . - ORM , - ;

    -- (- ). ORM - ;

    - , - .

    - bottleneck-;.

    - ( () (, -));

    60

  • PHP Inside 3 I.

    ;

    ;

    ER- , ORM(CMS frameworks: );

    - ( , ). - .

    .

    (A) - ORM, (B)

    1. : (B) , (A) ( );

    2. : (A) RAD-;

    3. : (A) - - , ORM - . ( ORM- - ).

    PHP - , Propel, http://propel.phpdb.org (2004)

    Meta Storage (MDB), http://www.meta-language.net (1999)

    PEAR::DB_DataObjects,http://pear.php.net/package/DB_DataObject (2002)

    PEAR::DB_QueryTool,http://pear.php.net/package/DB_QueryTool (2003)

    61

  • PHP Inside 3

    [Demiurg];

    [];

    [Yamert];

    [DAN];

    [SadSpirit], [email protected];

    [fisher];

    , [PHPclub];

    [Lenka];

    [young];

    ;

    [nw], PHP Inside, . ;

    [Dallas];

    ;

    http://phpclub.ru

    , ;

    [kosmonavt], http://kosmo.wmaster.ru, .

    [nw].

    ! :http://mag.phpclub.ru

    [email protected]

    http://phpclub.ru/talk

    62

  • PHP Inside 3

    ( )

    63

    Smarty - MySQL PHP: , XML- PostgreSQL? PEAR I. -