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

  • Published on
    23-Feb-2016

  • View
    222

  • Download
    0

DESCRIPTION

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

Transcript

<ul><li><p>5 !</p><p> MySQL (. 12)</p><p> PostgreSQL? (. 33)</p><p> PHP: (. 17)</p><p> -</p><p> 3 '04</p><p>2004</p></li><li><p>PHP Inside 3</p><p> ( )....................................................................................................1Smarty - ( )................................................................... 3 MySQL ( )....................................................12 PHP: , ( )............................................................. 17 XML- - ( )....................25 PostgreSQL? ( )........................................................................................... 33 PEAR - ( )...............42 I. ( )........................................................................................ 50 .................................................................................................................... 62</p><p> -</p><p> - - PHP, 14 . PHP(http://www.phpclub.ru) (http://www.3planeta.ru) - , -. - .</p><p>, , - . http://phpclub.ru/talk , , - . .</p><p> , , , - .</p><p> [Yamert], . , , [PHPClub], , - ( - ).</p><p> [Sad Spirit], , : PEAR PostgreSQL. - , - : -, - .</p><p> [Demiurg], - . Smarty , , -. : - .</p><p>1</p><p> : </p></li><li><p>PHP Inside 3</p><p> [], . , , MySQL , MySQL.</p><p> [fisher] - , - , .</p><p> [DAN], , , - XML-.</p><p> - , , -, .</p><p> , , , . - ? .</p><p> , , .</p><p> - . , . , , , , - . </p><p> - , ., , (http://phpclub.ru) (http://www.3planeta.ru).</p><p>2</p><p> .</p></li><li><p>PHP Inside 3 Smarty - </p><p> Smarty - </p><p> , PHP , HTML. , , PHP, PHP- HTML. , , , html (, , ). -. -, . . - PHP- HTML. - .</p><p> , . HTML ( ), - . PHP- HTML , , , , - HTML.</p><p> -</p><p> , Model/View/Controller (MVC). MVC (Model), (View) -(Controller). , -, . , - , . , - . - markup language ( ). controller, , -. PHP.</p><p> MVC WEB, , , </p><p> . PHP- (Controller). , (Model), (View), , -. , .</p><p>3</p><p> : </p></li><li><p>PHP Inside 3 Smarty - </p><p>. 2. -</p><p> , ( ). , -. , , - . </p><p>Smarty VS Others </p><p> Smarty. , Smarty - - , HTML . Smarty Sigma PEAR.</p><p>4</p><p>. 1. MVC</p></li><li><p>PHP Inside 3 Smarty - </p><p> Sigma. </p><p>:</p><p>:</p><p> Smarty.</p><p>:</p><p>5</p><p> {first_name} {last_name} </p></li><li><p>PHP Inside 3 Smarty - </p><p>:</p><p> , Smarty , . , Smartyc Smarty , . Sigma , , HTML-- . , Smarty , Sigma . </p><p> . , . - . - . , , , , , , , . . Smarty , , - , . </p><p>, -. , , , -, - . Smarty, , - . , , - , , , - , . , , .</p><p>, Smarty Smarty. Smarty -</p><p> , . </p><p>Smarty (compiling PHP template engine). , , , PHP-.</p><p> - , . , , - , . , . </p><p>6</p><p>{foreach name=outer item=contact from=$contacts} {foreach key=key item=item from=$contact} {$key}: {$item} {/foreach}{/foreach}</p></li><li><p>PHP Inside 3 Smarty - </p><p> -, . ,, PHP-, , - , . </p><p> , , Smarty -</p><p>, , , , . , -. , Smarty , -, . - section. :</p><p> :</p><p> , Smarty :</p><p> foreach , . - : sectionelse foreachelse, - , . </p><p>:</p><p> , , , , .. </p><p> (if). , </p><p> - php. </p><p>7</p><p>{section name=customer loop=$custid} id: {$custid[customer]} {/section}</p><p>id: 1000id: 1001id: 1002</p><p>{_ 1=1 2=2 ...}_</p><p>{/_ }</p><p>{_ 1=1 2=2 ...}</p><p>{section name=customer loop=$custid} id: {$custid[customer]}{sectionelse} there are no values in $custid.{/section}</p></li><li><p>PHP Inside 3 Smarty - </p><p> :</p><p> , </p><p>:</p><p>C , Smarty , -. </p><p> Smarty </p><p> . Smarty , . - function._.php php- smarty_function__($params, &amp;$smarty), . , , $params. :</p><p> Smarty , -</p><p> . , , , html, :</p><p>8</p><p>{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}</p><p>{assign var="name" value="Bob"}</p><p>function smarty_function_eightball($params, &amp;$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];}</p><p>{$str|escape:"html"}</p></li><li><p>PHP Inside 3 Smarty - </p><p> :</p><p>, , - . . modifier._.php PHP- smarty_modifier_ _ ($string). -:</p><p> , -, , - PHP- . , - str_repeat:</p><p> Smarty -</p><p> . , , - . - :</p><p> - config_load. , , . , - . </p><p> - {#_#} {$smarty.config. _}.</p><p>9</p><p>{$str|escape:"html"|upper}</p><p>function smarty_modifier_capitalize($string){ return ucwords($string);}</p><p>{$str|str_repeat:3}</p><p># 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."""</p></li><li><p>PHP Inside 3 Smarty - </p><p> , , Smarty -</p><p> . , - , - , PHP, - , , , . , , - . </p><p>, , Smarty (: Fatal error: Smarty:[in index.tpl line 28]: syntax error: missing section name in /path/to/smarty/Smarty.class.php on line 1041). </p><p> , Smarty MVC . , MVC - , - , View-,, .</p><p> , , Smarty - View- ( -). , , popup- . . </p><p> Smarty , , </p><p> . , Smarty , , . </p><p> : ? Smarty -, . , . </p><p> , - . . </p><p>, , -, . </p><p>10</p></li><li><p>PHP Inside 3 Smarty - </p><p>Smarty - cache_id, :</p><p>Cache_id , . , . - , cache_id group|subgroup|id. </p><p>, , , . , - . </p><p>, Smarty -. , -, , (, )? . </p><p>, Smarty insert. insert PHP-. , . , View Controller.</p><p> , Smarty -</p><p> - WEB-. HTML PHP- - , . , . Smarty , , Smarty -. http://smarty.php.net/ </p><p>11</p><p>$smarty-&gt;caching = true;$my_cache_id = $_GET['article_id'];if(!$smarty-&gt;is_cached('index.tpl',$my_cache_id)) { // No cache available, do variable assignments here. $contents = get_database_contents(); $smarty-&gt;assign($contents);}$smarty-&gt;display('index.tpl',$my_cache_id);</p></li><li><p>PHP Inside 3 MySQL</p><p> MySQL 4.1</p><p> 4.1 . :</p><p> . 4.1. - , , , - Unicode (utf8 ucs2). ;</p><p> GIS. MyISAM . OpenGIS. - :</p><p> SRS (Spatial Reference System), , ;</p><p> ;</p><p> (prepared statements ). - MySQL - :</p><p> ;</p><p> ;</p><p> 4.1 . - , . , - ( 4.1), - MySQL :</p><p> , :</p><p>1. ;</p><p>2. MySQL -old-passwords.</p><p> GROUP_CONCAT(), ();</p><p>12</p><p>CREATE TABLE t1(l1 LINESTRING);INSERT INTO t1 VALUES(LineStringFromText('LINESTRING(0 0, 1 1, 2 2)'));</p><p>Client does not support authentication protocol requestedby server; consider upgrading MySQL client</p><p> : </p></li><li><p>PHP Inside 3 MySQL</p><p> WITH ROLLUP, - GROUP BY. ROLLUP - . :</p><p> ONDUPLICATE KEY UPDATE INSERT.</p><p>INSERT .. ON DUPLICATE KEY UPDATE - - .</p><p> TIMESTAMP DEFAULTCURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.</p><p> DEFAULT CURRENT_TIMESTAMP TIMESTAMP , INSERT , ON UPDATE CURRENT_TIMESTAMP, - UPDATE.</p><p> CREATE TABLE - :</p><p>13</p><p>mysql&gt; 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)</p><p>CREATE TABLE t1(dt timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,id int);CREATE TABLE t2(dt timestamp DEFAULT CURRENT_TIMESTAMP,id int);</p></li><li><p>PHP Inside 3 MySQL</p><p> 5.0 5.0 -</p><p> . SQL-, . MySQL SQL:2003. DB2.</p><p> :</p><p> . ASENSITIVE,READ ONLY -SCROLL.</p><p> 5.0 (VIEW). (derived tables), - FROM, 4.1.</p><p> 5.0 VIEW, 5.1.</p><p> : -</p><p> MySQL (MySQL Core Certification) - MySQL (MySQL Professional Certification).</p><p> . , - SQL, MySQL, - , MySQL AB, ..</p><p> 70 , 1,5 , .</p><p> :</p><p>http://www.mysql.com/training/certification/selftest/core/index.php </p><p>, , - , -, , , MySQL. , - InnoDB, .</p><p> 70 , - 1,5 .</p><p>14</p><p>CREATE PROCEDURE proc1 (IN param1 INT,OUT param2 INT)BEGINSELECT SQRT(param1) INTO param2;END</p><p>CREATE FUNCTION func1 (name CHAR(20)) RETURNS CHAR(50)RETURN CONCAT(name,' - kanistra!');</p></li><li><p>PHP Inside 3 MySQL</p><p> - 135 .</p><p> MySQL . </p><p> MySQL GNU GPL .</p><p> GPL MySQL -. , - . , , , MySQL, .</p><p> , GPL, MySQL .</p><p> MySQL GPL , - GPL . </p><p> , - , , , - , :</p><p>1. GNU GPL , - , - , ;</p><p>2. , - - , ;</p><p>3. MySQL , ;</p><p>4. , , GPL - MySQL AB.</p><p> - MySQL:</p><p> /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</p><p>15</p></li><li><p>PHP Inside 3 MySQL</p><p> /Common Public License 1.0GNU General Public License(GPL)</p><p>2.0</p><p>GNU Library "Lesser"General Public License(LGPL)</p><p>2.1</p><p>Jabber Open Source License 1.0MIT license -Mozilla Public License (MPL) 1.0/1.1PHP License 3.0Python license (CNRI PythonLicense)</p><p>-</p><p>Python Software FoundationLicense</p><p>2.1.1</p><p>Sleepycat License 1999W3C License 2001Zlib/libpng License -Zope Public License 2.0</p><p> , -:</p><p> - GPL , FreeSoftware Foundation OSI, GPL;</p><p> - - GPL, - MySQL;</p><p> , , licensing@mysql.com.</p><p> , , . .</p><p> - MySQL , .</p><p>16</p></li><li><p>PHP Inside 3 PHP: , </p><p> PHP: , - -</p><p> PHP? </p><p> PHP, -, - . , - ; , , , . , - - PHP - - (), -. </p><p> , , , </p><p>:</p><p>1. . -, , - , ( - ), - - , - . , , . - () () , , (, LDAP), ;</p><p>2. . -, , - , -. . , , , ;</p><p>3. . , - , . , Logger ( ..). : FileLogger DBLogger , , - . ;</p><p>, , PHP 4:</p><p>1. public static. private protected ( PHP 5) , - , , - ;</p><p>17</p><p> : </p></li><li><p>PHP Inside 3 PHP: , </p><p>2. . - ( );</p><p>3. , - $this-&gt;... .</p><p> MVC: </p><p> MVC (Model-View-Controller, --). - 3 , :</p><p>1. . , ;</p><p>2. , -;</p><p>3. , - , . , - .</p><p> 3 - :</p><p>1. ;</p><p>2. ( -HTML, . WML, ..) - . ; - ;</p><p>3. , .</p><p>, .</p><p>18</p><p>. 1. .</p></li><li><p>PHP Inside 3 PHP: , </p><p> 1 , - , :</p><p>1. client ( ). product, ( order), ;</p><p>2. product ( ), - . ( , &amp;). - Supplier;</p><p>3. product_category ;</p><p>4. order , : , .;</p><p>5. supplier , .</p><p> ( MVC). </p><p> 2 , - , MVC-. (.. ).</p><p> ShopModule ( Registry, ) . protected- log(), . </p><p> name( ), log_engine ( - ( , PEAR::Log)), db_engine ( ), config (. ).</p><p>19</p><p>.2 .</p></li><li><p>PHP Inside 3 PHP: , </p><p> WebInterface . protected-handleGETRequest(), handlePOSTrequest() - . ( , - , - , HTTP- - ). </p><p> , - (, CartInterface ) activate(). - , , , - . , , - CartInterface, activate().</p><p> WebLogic . , - , (getProducts()), (buyProduct()) (getOrderStatus()).</p><p> WebView . , - model. , tpl_engine (, PEAR::Sigma), - . - , printErrorForm(), - . WebView, ( PC, ., PDA). PC.</p><p>20</p><p> 3. MVC .</p></li><li><p>PHP Inside 3 PHP: , </p><p> MVC, Registry(..4), - , .. </p><p> , . - . ( ShopModule) . .</p><p> (static), ( final).</p><p> . .</p><p>21</p><p>. 4. .</p><p>.5. -.</p></li><li><p>PHP Inside 3 PHP: , </p><p> , .1, .</p><p>, ( ). , DBEntity : </p><p> init() , , , - ;</p><p> update(), delete(), insert() . SQL-;</p><p> getTableName() ;</p><p> getField() . ( - fields);</p><p> setField() . .</p><p> -, , init(), get- set-.</p><p> , - ( , Client block() activate ()).</p><p> .</p><p>22</p><p>.6. .</p></li><li><p>PHP Inside 3 PHP: , </p><p> PHP5 - PHP?</p><p> , PHP5 . , ( ):</p><p>1. (try/catch );</p><p>2. private, protected, public;</p><p>3. abstract, final;</p><p>4. ;</p><p>5. static- ( );</p><p>6. .</p><p> , : - , .</p><p> PHP. , , , - , , ZE2.</p><p>23</p><p>.7. (2 ).</p></li><li><p>PHP Inside 3 PHP: , </p><p> :</p><p>1. , - , (overloading) ;</p><p>2. - ;</p><p>3. , static, , $this, - , . -, ;</p><p>4. , .</p><p>, , PHP4 PHP5:</p><p>1. empty;</p><p>2. , __construct(), ;</p><p>3. , .</p><p>, -, , - PHP4 .</p><p> PHP4 PHP5 PHP4 -</p><p> :</p><p> :</p><p> ;</p><p> try/catch - .</p><p> PHP5 .</p><p>24</p></li><li><p>PHP Inside 3 XML- -</p><p> XML- -</p><p> - , - XML (eXtensible Markup Language). - , - . - W3C, xml- - , . , xml--. xml-.</p><p> XML PHP 4 XML PHP 3- </p><p> PHP. xml-- php- -, , PHP. xml- - xml-:</p><p>1. SAX (Simple API for XML) -;</p><p>2. DOM (Document Object Model) .</p><p>SAX- php- xml expat. -: .</p><p>DOM- php-domxml libxml. .</p><p>25</p><p>. 1. XML PHP 4.</p><p> : </p></li><li><p>PHP Inside 3 XML- -</p><p> SAX- , (parsing) - . , - . , DOM- , . , SAX- , .</p><p> , xml- php-. , domxml. - , php- xml. -, .</p><p> XSLT PHP 4XSLT (XSL Transformations) xml-</p><p> (eXtensible StylesheetLanguage).</p><p> PHP 4 API : sablotron ( xslt) libxslt( domxml). API xml-. </p><p> , API domxml xslt - , , PHP - . , domxml DOM - W3C. </p><p> PHP - , , , , - - . - ,...</p></li></ul>