Журнал о рыбалке

70
# 0 PHP Inside 25 02 2004 Русский журнал web разработчика Стандарты кодирования на PHP Дополнительные возможности JpGraph JpGraph – объектно-ориентированная PHP-библиотека, позволяющая достаточно просто создавать высококачественную профессиональную графику Они делают это так Интервью с Президентом New York PHP – Хансом Заунером, специально для нашего журнала PHP5 - не революция, а эволюция Расмус Лердорф для Linuxworld Программирование для WEB

description

Журнал о рыбалке

Transcript of Журнал о рыбалке

  • # 0

    PHPInside25 022004 web

    PHP

    JpGraph

    JpGraph -PHP-,

    New York PHP ,

    PHP5 - ,

    Linuxworld

    WEB

  • 2

    JpGraph ..3

    JpGraph .5

    ....20

    : , ...22

    PEAR.....23

    PHP......28

    PEAR40

    FPDF....45

    54

    : [email protected] [email protected]

    !

    . 0. , , , , .

    , ,, , . PHPClub Team ( ). , , , phpmagazine php|architect.

    , , , , . . !

  • 3

    JpGraph http://detail.phpclub.ru http://blog.redgraphic.ru/as/06-08-03_78/ :

    , PHP, JpGraph(http://www.aditus.nu/jpgraph/). , , JpGraph - PHP, . , , excel, . GD(http://www.boutell.com/gd/).

    , , - , , - . JpGraph :

    // Special unicode language support

    DEFINE("LANGUAGE_CYRILLIC",true);

    // If you are setting this config to true the conversion

    // will assume that the input text is windows 1251, if

    // false it will assume koi8-r

    DEFINE("CYRILLIC_FROM_WINDOWS",true);

    - . , xxx., . . JpGraph( , GD) TTF-. , unix', windows'. , , .

    JpGraph', .

    , :

    1. . /usr/X11R6/lib/X11/fonts/TrueType/ /usr/X11R6/lib/X11/fonts/TTF/.

    2. , ( - , ).

    3. , , , Winnt/fonts .

    4. JpGraph DEFINE("TTF_DIR", ...) , .

    JpGraph . , , Verdana ( ):

    $somegraph->title->SetFont (FF_VERDANA);

    , , ( ) JpGraph , TTF- (FreeType). , , PHP.

    (- !) , PHP --with-freetype-dir=/usr, /usr freetype,

  • 4

    JpGraph ______________________________________

    , , fontov ( ).

    . , (, , windows), :

    DEFINE("CYRILLIC_FROM_WINDOWS",true);

    , , . . , SetFont(). .

  • 5

    JpGraph : (Jason E. Sweat) : : http://phparch.com/issuedata/articles/article_40.pdf

    JpGraph (http://www.aditus.nu/jpgraph/) - PHP-, , . , JpGraph, :

    JpGraph;

    ( );

    JpGraph ;

    - ( CSIM, .Client Side Image Map. . .) .

    : PHP: - 4.0.4, - 4.1 : : JpGraph, GD PHP

    JpGraph , : http://www.aditus.nu/jpgraph/jpdownload.php. , PHP include_path. , . jpgraph.php.

    /Examples/testsuit.php. 200 , JpGraph, , . JpGraph , . http://www.aditus.nu/jpgraph/jpdownload.php , . JpGraph http://jpgraph.fan-atics.com/. PHP 4.3.0 ( GD2), Apache 1.3.27 RedHat Linux 7.2.

    MySQL (http://www.mysql.com) ADOdb (http://php.weblogs.com/adodb) . phpa_db.inc.php, 1.

    : JpGraph. , , URI 1.14, . . Windows 2000 Server SP4/Apache 1.3.27/PHP 4.3.3 (. Apache)/JpGraph 1.14/MySQL 4.1-alpha.

  • 6

    JpGraph_____________________________

    - ADOdb - $conn, . Connect() , .

    : , : $conn->Connect('localhost', 'username', 'passwd', 'dbname'); ADOdb , PHP include_path. , ADOdb, . ADOdb SQL- : $rs = $conn->Execute($sql_statement, $bind_array); , - ADOdb, FALSE. : GetArray() GetAssoc(). GetArray() , COLUMN => VALUE. GetAssoc()

    , . , TrueType Arial, JpGraph . FF_ARIAL FF_FONT1. FF_FONT1 , FF_ARIAL, . , . .

    ABC, . ABC B $12.99 E - $1,499.50. , . : , , . , . . ABC , , . .

    1: phpa db.inc.php

  • 7

    JpGraph_____________________________

    ABC . abc_sales. , , , , , . , - abc_catalog, abc_channel, abc_forecast, abc_region abc_state_region. abc_catalog , , . abc_channel , (web, , ), . abc_forecast , . . abc_region . abc_state_region .

    SQL-, , , mysql_ddl.sql . , abc_gen_sales.php abc_fcst_ins.php . abc_gen_sales.php , abc_fcst_ins.php , . : 2000 .

    ( ASCII-) http://www.census.gov/geo/www/gazetteer/tiger/tms/gazetteer/ustracts2k.zip

    :

    1. , .

    2. jvn_parse_census.php ( - . ) ustracts2k.txt ( ASCII), census_data, abc_gen_sales.php.

    3. mysql_ddl.sql. 4. abc_gen_sales.php. 5. abc_fcst_ins.php.

    : 2002 , , 15 2002 , . 2003 , , . : 2004 , .

    , . , .

  • 8

    JpGraph_____________________________

    PHP-, JpGraph, 4- :

    1. .

    2. Graph ( ).

    3. Plot, Graph.

    4. Graph .

    , , . , ADOdb ,

    26-122 abc_reg_sales_graph.php. , . , . , $region_id, . . , , HTML- , . :

    2: (abc_reg_sales_graph.php)

    1 $region_id = check_passed_region('region'); 2 if (!$region_id) { 3 graph_error('region parameter incorrect'); 4 } 5 6 function check_passed_region( $parm ) 7 { 8 global $regions; 9 10 if (array_key_exists($parm,$_GET)) { 11 $val = $_GET[$parm]; 12 if (array_key_exists($val, $regions)) { 13 return $val; 14 } 15 } 16 return false; 17 } 18 19 function graph_error($msg) 20 { 21 $graph = new CanvasGraph(WIDTH, HEIGHT); 22 23 $t1 = new Text($msg); 24 $t1->Pos(0.05, 0.5); 25 $t1->SetOrientation('h'); 26 $t1->SetFont(FF_ARIAL, FS_BOLD); 27 $t1->SetColor('red'); 28 $graph->AddText($t1); 29 30 $graph->Stroke(); 31 exit; 32 }

  • 9

    JpGraph__________________________

    (, PHP), , , , . , 2, . , - $regions. , jpgraph.php jpgraph_canvas.php. , . , . , ,

    $graphData, , . 3 $graphData, . : , . , , . .., : $gty = array(...); $f_gty = array(...); : $graphData = array ( gty => array(...), f_gty => array() );

    3: $graphData (abc_reg_sales_graph.php)

    1 $graphData['f_qty'] = array(); 2 $graphData['labelX'] = array(); 3 for ($i=0,$j=count($salesData); $i

  • 10

    JpGraph_____________________________

    , . . 4 , . JpGraph API. , , , . 4- , . 2 Graph. 3 BarPlot LinePlot. 4, - Graph::Stroke() . Graph::Stroke() JpGraph . . 1.

    ( ..) , ( ). . , , . , , 5. 2.

    4:

    $graph = new graph(WIDTH, HEIGHT); $graph->SetScale('textlin'); $b1 = new BarPlot($graphData['qty']); $l1 = new LinePlot($graphData['f_qty']); $graph->Add($b1); $graph->Add($l1); $graph->Stroke();

    1.

  • 11

    JpGraph_____________________________

    JpGraph . . . -, , , .

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

    5: , . 2

    $b1 = new BarPlot($graphData['rev']); $l1 = new LinePlot($graphData['f_rev'])$l1->SetStepStyle(); $l1->SetColor('darkgreen'); $l1->SetWeight(3);

    2. .

  • 12

    JpGraph_____________________________

    , . .

    JpGraph , , , . . 7. (. . 3) , 8.

    6: , (abc reg sales graph.php)

    for ($i=0,$j=count($graphData['labelX']); $iy2axis->SetLabelFormatCallback ('y_fmt_dol_thou'); function y_fmt_dol_thou($val) { return '$'.number_format($val/1000); }

    8: . 3

    1 $graph->SetY2Scale('lin'); 2 $graph->SetY2OrderBack(false); 3 4 //generate the individual plots 5 $b1 = new BarPlot($graphData['qty']); 6 $b2 = new BarPlot($graphData['rev']); 7 $b2->SetFillColor('lightgreen'); 8 $b1z = new BarPlot($graphData['zero']); 9 $b2z = new BarPlot($graphData['zero']); 10 $l1 = new LinePlot($graphData['f_rev']); 11 $l1->SetStepStyle(); 12 $l1->SetColor('darkgreen'); 13 $l1->SetWeight(3); 14 15 //create the grouped plots 16 $gb1 = new GroupBarPlot(array($b1, $b1z)); 17 $gb2 = new GroupBarPlot(array($b2z, $b2)); 18 19 //add the plots to the graph object 20 $graph->Add($gb1); 21 $graph->AddY2($gb2); 22 $graph->AddY2($l1);

  • 13

    JpGraph_____________________________

    , . ,

    . , , 9. . 4.

    . 3. , .

    9: , . 4 (abc_reg_sales_graph.php)

    1 $colors = array('pink', 'orange', 'yellow', 'lightgreen', 'lightblue'); 2 3 $abqAdd = array(); 4 $abrAdd = array(); 5 for($i=0,$j=count($items); $iSetFillColor($colors[$i]); 9 $b1->SetLegend($items[$i]['item_desc']); 10 $abqAdd[] = $b1; 11 12 $b2 = new BarPlot($graphData[$key]['rev']); 13 $b2->SetFillColor($colors[$i]); 14 $abrAdd[] = $b2; 15 } 16 $ab1 = new AccBarPlot($abqAdd); 17 $ab2 = new AccBarPlot($abrAdd); 18 $b1z = new BarPlot($graphData['zero']); 19 $b2z = new BarPlot($graphData['zero']); 20 21 $gb1 = new GroupBarPlot(array($ab1, $b1z)); 22 $gb2 = new GroupBarPlot(array($b2z, $ab2)); 23 24 $graph->Add($gb1); 25 $graph->AddY2($gb2);

  • 14

    JpGraph_____________________________

    . , , , , . , , . , . , ABC Co.Proprietary ( ABC - . .), . , , , . Graph::AdjBackgroundImage(), , . .

    img/abc-background.png , . , 10. : GD2, PHP 4.3.0, Graph::AdjBackgroundImage(). PHP, .

    . 4. .

    10: (abc_reg_sales_graph.php)

    if (USING_TRUECOLOR) { $graph->SetBackgroundImage('img/background_prefade.png', BGIMG_FILLFRAME); } else { //AdjBackgroundImage only works GD, not GD2 true color $graph->SetBackgroundImage('img/background.png', BGIMG_FILLFRAME); $graph->AdjBackgroundImage(0.9, }

  • 15

    JpGraph_____________________________

    , 11, ,

    , . . 5.

    11: . 5 (abc_reg_sales_graph.php)

    1 $graph->title->Set(date('Y')." Sales for{$regions[$region_id]} Region"); 2 $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); 3 $graph->SetMarginColor('white'); 4 $graph->yaxis->title->Set('Left Bar Units Sold'); 5 $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10); 6 $graph->yaxis->SetLabelFormatCallback('y_fmt'); 7 $graph->yaxis->SetTitleMargin(48); 8 $graph->y2axis->title->Set('Right Bar Revenue ( $ 000 )'); 9 $graph->y2axis->title->SetFont(FF_ARIAL, FS_BOLD, 10); 10 $graph->y2axis->SetTitleMargin(45); 11 $graph->y2axis->SetLabelFormatCallback('y_fmt_dol_thou'); 12 $graph->xaxis->SetTickLabels($graphData['labelX']); 13 14 $graph->legend->Pos(0.5, 0.95, 'center', 'center'); 15 $graph->legend->SetLayout(LEGEND_HOR); 16 $graph->legend->SetFillColor('white'); 17 $graph->legend->SetShadow(false); 18 $graph->legend->SetLineWeight(0);

    . 5.

  • 16

    JpGraph_____________________________

    JpGraph . . , , , JpGraph , . , . Graph , , (, , ) , , , JpGraph , . , PHP- src img. , , 12. , 24 , , , new Graph().

    , Graph , .

    , , . , . , . , , 22-82 abc_map_graph.php , , . 13 , , . 6.

    12: , . (abc_reg_sales_graph.php)

    define('GRAPH_NAME', 'abc_reg_sales'); $graphName = GRAPH_NAME.$region_id.'.png'; $graphTimeout = 60*24; $graph = new graph(WIDTH, HEIGHT, $graphName, $graphTimeout, true);

    13: . 6

    $sliceColors = array('lightgreen', ''lightblue'); $graph = new PieGraph(WIDTH, HEIGHT)$graph->title->Set($regions[$region]['region'].' Region'); $graph->subtitle->Set('Sales by Chansince '.GRAPH_START); $p1 = new PiePlot($graphData[$pickRegion]['rev$p1->SetLegends($graphData[$pickRegion][]); $p1->SetSliceColors($sliceColors); $graph->Add($p1); $graph->Stroke();

  • 17

    JpGraph_____________________________ JpGraph_____________________________

    , , . , ABC. , . img/abc-regions.png .

    $graphData, : $graphData['r'.$rIndex]['map_x'] = $regionData[$i]['map_x']; $graphData['r'.$rIndex]['map_y'] = $regionData[$i]['map_y']; 14, , . 7.

    . 6.

    14: . 7 (abc_map_graph.php)

    1 $graph = new PieGraph(WIDTH, HEIGHT); 2 $graph->SetBackgroundImage('img/abc-regions.png', BGIMG_FILLFRAME); 3 4 for ($i=0; $iSetCenter($graphData[$pickRegion]['map_x'], 9 $graphData[$pickRegion]['map_y']); 10 $p1->SetSize(PIE_SIZE); 11 $p1->SetLabels($graphData[$pickRegion]['revFmt']); 12 $p1->SetSliceColors($sliceColors); 13 if (!$i) { 14 $p1->SetLegends($graphData['label']); 15 } 16 17 $graph->Add($p1); 18 } 19 20 $graph->legend->Pos(0.9, 0.85, 'center', 'center'); 21 $graph->Stroke();

  • 18

    , . , - (Client Side Image Maps CSIM . .). CSIM HTML-, . CSIM ( ). , : define('DRILL_GRAPH', 'abc_reg_sales_graph.php?region='); $graphData : $graphData['r'.$rIndex]['targets'][] = DRILL_GRAPH.$regionData[$i]['region_id']; $graphData['r'.$rIndex]['alts'][] = "Click for more information regarding {$regions[$rIndex]['region']} sales.";

    HTML (CSIM), . CSIM . , . - img . , JpGraph, , , . img , . . , . (. 14 . .): $p1->SetCSIMTargets( $graphData[$pickRegion]['targets'],

    $graphData[$pickRegion]['alts'] );

    . 7.

  • 19

    JpGraph_____________________________

    , 15. JpGraph img/abc_channel_graph.png. $imgMap -. img , -. , JpGraph:

    JpGraph , ;

    ;

    ;

    ;

    ;

    ;

    JpGraph , CSIM;

    ( );

    -

    JpGraph API, . JpGraph PHP web. JpGraph : , - ., PHP JpGraph data mining.

    15: CSIM (abc_map_graph.php)

    define('IMG_DIR', 'img/'); $graphName = IMG_DIR.'abc_channel_graph.png'; $graph = new PieGraph(WIDTH, HEIGHT); //the rest of the graph code... $graph->Stroke($graphName); $mapName = 'ABC_Region_Drill'; $imgMap = $graph->GetHTMLImageMap($mapName); print

  • 20

    . New York PHP . nw

    - PHP (NYPHP) , PHP (Apache+MySQL+PHP). , . PHP/AMP, Open Source, , .NYPHP - , AMP. , . NYPHP . , . Open Source , . AMP , LAMP. Linux+Apache+MySQL+PHP/Perl/Python. NYPHP , . NYPHP (HansZauner) . . NYPHP nw: ? HansZ: . nw: ? .

    HansZ: 1000+ nw: ( ) , nyphp.com? HansZ: nyphp.org, phundamentals.nyphp.org. CMS community.nyphp.org. - nw: - ( , )? HansZ: , , . -. , , . . nw: , - ? HansZ: ? . , . . nw: ? HansZ: . , . Becks, Guiness Weisse. nw: , ( )?

    : . , , .

  • 21

    _____________________________________________

    HansZ: . . nw: ( IDE, web , , )? HansZ: Zend Studio, , , (UltraEdit,vi ). Dreamviewer, Homesite GoLive. Apache MySQL, , IIS, Oracle MSSQL .

    nw: , , . . ()? HansZ: -, . , , , .nw: ! HansZ: . , , , . , , New York PHP.http://nyphp.com

  • 22

    : , : http://www.linuxworld.com.au/index.php?id=1241831333&fp=2&fpid=1 : nw

    5 , , , - . LinuxWorld, , web , . , 5 Java XML. 5 , 1994 , .

    ( ) - - (open source), web . , .

    ,

    . . .

    , . 2002, NetCraft web, . , 15 .

    800-900. , , - , , , .

    , , , . 10 .

    (open source) , . , - .

    ,

    , web , web- .

    , web, -

    . web, , . . - ( 3) http://www.php.net.

    linux.conf.au, ()14 17 2004 ( . ). .

  • 23

    PEAR http://www.pear.php.net

    : PEAR , PEAR, PHP PEAR.

    4 , . Emacs , indent-tabs-mode . 1 Emacs :

    VIM: set expandtab set shiftwidth=4 set tabstop=4

    if, for, while, switch, . if, :

    if ((condition1) || (condition2)) { action1; } elseif ((condition3) && (condition4)) { action2; } else { defaultaction; }

    , .

    , , . .

    C switch: switch (condition) { case 1: action1; break; case 2: action2; break; default: defaultaction; break; } , .

    (defun php-mode-hook () (setq tab-width 4 c-basic-offset 4 c-hanging-comment-ender-p nil indent-tabs-mode (not (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name)) (string-match "\.php$" (buffer-file-name)))))) 1

  • 24

    PEAR____________________________________

    . , . :

    $var = foo($bar, $baz, $quux);

    , "=". , :

    $short = foo($bar); $long_variable = foo($baz);

    c:

    function fooFunction($arg1, $arg2 = '') { if (condition) { statement; } return $val; }

    . , . ( 2):

    PHPDoc, Javadoc. PHPDoc : http://www.phpdoc.de/

    , , PHPDoc, . : , , .

    C (/**/) C++ (//). Perl/shell (#) .

    (including)

    , , require_once(). - , include_once(). , .

    function connect(&$dsn, $persistent = false) { if (is_array($dsn)) { $dsninfo = &$dsn; } else { $dsninfo = DB::parseDSN($dsn); } if (!$dsninfo || !$dsninfo['phptype']) { return $this->raiseError(); } return true; } 2

  • 25

    PEAR____________________________________

    : include_once() require_once() , . , .

    PHP-

    PHP-. PEAR .

    PEAR ( 3):

    , , . , "" (.. 10%-20% ).

    .

    .

    , PEAR, , , . , .

    CVS

    , CVS cvs.php.net.

    CVS - $Id$

    . , , "Last Modified:" ..

    ,

    /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | [email protected] so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Original Author | // | Your Name | // +----------------------------------------------------------------------+ // // $Id$ 3

  • 26

    PEAR____________________________________

    CVS (branches).

    CVS , , . :

    RELEASE_n_n

    (). . , , .

    QA_n_n

    (). , (releasecandidat), (branch) , . .

    MAINT_n_n

    (). "-" (, 1.2.1 .. 1.2), , , -.

    RELEASE, .

    ,

    1.2 "Money_Fast": $ cd pear/Money_Fast $ cvs tag RELEASE_1_2 T Fast.php T README T package.xml , - PEAR .

    QA:

    $ cvs tag QA_2_0_BP ... $ cvs rtag -b -r QA_2_0_BP QA_2_0 $ cvs update -r QA_2_0 $ cvs tag RELEASE_2_0RC1 ..., : $ cvs tag RELEASE_2_0 "QA_2_0_BP" - . . (MAINT branches) .

    URL

    "example.com" URL, RFC 2606.

    , "" , , .

    . , . . PEAR

  • 27

    PEAR____________________________________

    , . :

    Log Net_Finger HTML_Upload_Error

    " " ( - "" =)). , . , "" - . :

    connect() getData() buildSomeWidget()

    ( , ; PHP (?) ) . :

    _sort() _initTree() $this->_status

    . /, . , , DB::, "DB_".

    ,

    , . , PEAR , $_PEAR_destructor_object_list.

    TRUE, FALSE, NULL

    PHP TRUE, FALSE NULL .

  • 28

    PHP http://tony2001.phpclub.net : [tony2001] : http://alltasks.net/code/php_coding_standard.html : (Fredrik Kristiansen)

    , , . , , , . - , , . , :

    , ;

    ;

    PHP , ;

    PHP "" , ;

    ;

    :-)

    :

    , - , , PHP;

    , - , , ;

    ;

    ;

    ;

    .

    : . , - ? , . , ! : . , , - . , , , , . "" , , , . "", "" , , . "" , . , , -

  • 29

    _PHP____________________________________

    . , : , - ;, - :-) , - , , ; , , . , . , .

    1. . 2. , -

    , .

    3. , .

    4. , .

    5. .

    - , . , , , . .

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

    , , , . , , ;

    , , , . . CRC , , ;

  • 30

    _PHP____________________________________

    , . , , ;

    . , , DownloadAgent ;

    , - ;

    - ; underscore- ('_').

    . class NameOneTwo class Name

    , - , , , : CheckForErrors() [()] ErrorCheck() [()]; DumpDataToFile() [()] DataFile()[()]. , . :

    Max - ;

    Cnt [count: , ] - - ;

    Key - . : RetryMax , RetryCnt - ;

    :

    Is - . Is, , ;

    Get - ; Set - .

    : IsHitRetryLimit() [: ?]. , , . : GetHTMLStatistic(). : GetHtmlStatistic(). , , -, , . , , NetworkABCKey. , C ABC K Key . , , ; .

  • 31

    _PHP____________________________________

    function FluidOz() // FluidOZ function GetHtmlStatistic() // GetHTMLStatistic class NameOneTwo { function DoIt() {}; function HandleError() {}; }

    - ;

    , .

    , . class NameOneTwo { function StartYourEngines(&$someEngine, &$anotherEngine) { $this->mSomeEngine = $someEngine; $this->mAnotherEngine = $anotherEngine; } var $mSomeEngine; var $mAnotherEngine; }

    ;

    underscore ('_').

    ;

    - .

    function HandleError($errorNumber) { $error = new OsError; $time_of_error = $error->GetTimeOfError(); $error_processor = $error->GetErrorProcessor(); }

    ;

    underscore ('_');

    ('-').

    , Magic Quotes . $myarr['foo_bar'] = 'Hello'; print "$myarr[foo_bar] world"; // : Hello world $myarr['foo-bar'] = 'Hello'; print "$myarr[foo-bar] world"; // warning

  • 32

    _PHP____________________________________

    , , . Magic Quotes. Magic Quotes, PHP , . $myarr['foo_bar'] = 'Hello'; $element_name = 'foo_bar'; print "$myarr[foo_bar] world"; // : Hello world print "$myarr[$element_name] world"; // : Hello world print "$myarr['$element_name'] world"; // parse error print "$myarr["$element_name"] world"; // parse error

    'g'.

    global $gLog; global &$grLog;

    PHP C GNU: underscore- ('_') .

    , . function some_bloody_function() { }

    , :

    1. :

    2. Unix- , , - :

    if ($condition) { while ($condition) { ... ... } }

    , . , . -

  • 33

    _PHP____________________________________

    . . (, vi), , . ? - . , , . , , . if ($very_long_condition && $second_very_long_condition) // { ... } else if (...) { ... }

    , . , . ()

    . ;

    ;

    return, .

    - .

    , . if (condition) { } while (condition) { } strcmp($s, $s1); return 1;

    //

    - 3-4 ;

    , . ;

    , , . , - , .

    , , ;

    . . 3-4 - ;

  • 34

    _PHP____________________________________

    , , , . , .

    function func() { if (something bad) // { if (another thing bad) // { while (more input) // { } } } }

    if then else . . : if (condition) // { } else if (condition) // { } else // { }

    else if, else . , .

    . : if ( 6 == $errorNum ) ...

    - , , ('=') . - , - . , . switch

    , ;

    default, , , , , ;

    - , case.

    switch (...) { case 1: ... // case 2: { $v = get_week_number(); ... } break; default: }

  • 35

    _PHP____________________________________

    continue, break ?: Continue break Continue break - goto, -. . goto, continue break , . - . continue :

    continue ;

    continue /.

    , : while (TRUE) { ... // ... if (/* - */) { continue; } ... // ... if ( $i++ > STOP_VALUE) break; }

    Note: " " , .

    : continue break - .

    ?: , ? :. :

    , ;

    , , ;

    , , else then .

    () ? funct1() : func2(); or () ? : ;

    ;

    ;

    & , .

  • 36

    PHP____________________________________

    var $mDate var& $mrDate var& $mrName var $mName $mDate = 0; $mrDate = NULL; $mrName = 0; $mName = NULL;

    . , . , - , - , - . , . . , - , , , . . , PHPDoc. PHPDoc .

    - , . - . . gotchas ["" ] , , , . . gotchas gotcha . , . . , . , . gotcha . gotcha, .

  • 37

    _PHP____________________________________

    gotchas

    :TODO:

    , , .

    :BUG: [id]

    , , ( ) .

    :KLUDGE:

    , , , , , .

    :TRICKY:

    , , , "" .

    :WARNING:

    -.

    :PARSER:

    - . ., .

    :ATTRIBUTE:

    .

    , .

    :

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

  • 38

    PHP____________________________________

    README :

    ;

    . , NAME ;

    ; :

    , online, , ;

    , - .

    , . , README, make- . , [framework]. . , . . -

    , . - , . . , () . : . , . . , . , , , . , . [] , . , , , . . , . , - . ,

  • 39

    _PHP____________________________________

    , . - . , , . . . - if(0): function example() { if (0) { } }

    /**/ , , , ?

    PHP Coding Standard Last Modified: 2003-02-17 The PHP Coding Standard is with permission based on Todd Hoff's C++ Coding Standard.

    Rewritten for PHP by Fredrik Kristiansen / DB Medialab, Oslo 2000-2003. Using this Standard. If you want to make a local copy of this standard and use it as your own you are perfectly free to do so. That's why we made it! If you find any errors or make any improvements please e-mail me the changes so I can merge them in. Recent Changes.

  • 40

    PEAR Maxim Matyukhin

    PEAR- php-. , pear PHP. PEAR. PEAR - , PHP. 100 . , pear- . pear: http://pear.php.net pear-. 1. HTML::Select (http://pear.php.net/HTML_Select ) SELECT- . : HTML::Select. ( name SELECT)

    loadArray() , SELECT , . HTML: SELECT- . loadQuery: loadQuery() pear::DB dsn- ( pear::DB). HTML_Select_Common (http://pear.php.net/HTML_Select_Common). SELECT- , .. SELECT :

    value1 value 2 value 3

  • 41

    PEAR____________________________________

    SELECT- . : 2. HTTP::Download (http://pear.php.net/HTTP_Download ) . , , . ( ): . 3. HTML::BBCodeParser (http://pear.php.net/HTML_BBCodeParser ) , , BB-, ( phpBB, VBulletin .).

    BB- HTML-: , : , BB-: - [b], [i], [u], [s], [sup], [sub] e-mail, ,, .. , , . 4. HTML_Crypt (http://pear.php.net/HTML_Crypt ). , . PHP, . e-mail

    , pear- ?

  • 42

    PEAR____________________________________

    : HTML- ( 1):

    ( js- ). HTML- , e-mail. 5. HTML::treeMenu (http://pear.php.net/HTML_treeMenu ) :-) DHTML-. , . 2.

    1

    HTML_Crypt, var a,s,n; function ja4fc707c63aa221b5326b8c0cb348e87(s){ r=''; for(i=0;i=8364){n=128;} r+=String.fromCharCode(n-3); } return r; } a='?d#kuhi@%pdlowr=plnhCeoxhurrw1qhw%APlfkdho#Gudqvilhog?2dA'; document.write (ja4fc707c63aa221b5326b8c0cb348e87(a)); var a,s,n; function da4fc707c63aa221b5326b8c0cb348e87(s) { r=''; for(i=0;i=8364){n=128;} r+=String.fromCharCode(n-3); } return r; } a='?d#kuhi@%pdlowr=pd{Czhevfulsw1ux%Apd{Czhevfulsw1ux?2dA'; document.write (da4fc707c63aa221b5326b8c0cb348e87(a));

  • 43

    PEAR____________________________________

    , , , .

    6. Archive::Tar (http://pear.php.net/Archive_Tar ) .tar.gz. , , , ZLib

    2

  • 44

    PEAR____________________________________

    . . : archive.tar.gz, /dir/to/archive/ file.txt . zip- ., , . 7. MP3::ID (http://pear.php.net/MP3_ID ) , MP3-, .MP3::ID ID3- MP3-.

    : . , , . : http://pear.php.net - PEAR. http://news.php.net/group.php?group=php.pear.dev - pear

  • 45

    FPDF. : nw fpdf Adobe Sys. Inc

    1. PDF web- PHP PDF . Adobe SystemsIncorporated. ,THE ADOBE PORTABLE DOCUMENTFORMAT (PDF) , AdobeAcrobat. , . PDF , . , , . , web- , , , . . PDF, , , PDF HTML . PHP, web-, PDF . . ,

    PDFLib, ClibPDF PHP FPDF. 2. FPDF PHP PDFLib ClibPDF PHP, FPDF PHP include() . www.fpdf.org. () , . : FPDF is Freeware (it is stated at the beginning of thesource file). There is no usage restriction. You mayembed it freely in your application (commercial ornot), with or without modification. . . 3. (, ) . ( ) . , FPDF . , . . , wintel (,

  • 46

    FPDF_______________________________________________

    *nix

    ). windows ( PostScript) TTF (True Type Font). - AFM ( ). , AFM TTF. AFM . , ttf2pt1. True Type PFB. , /fonts( Windows) .TTF . :http://ttf2pt1.sourceforge.net http://fpdf.org/fr/dl.php?id=22 (Windows). , , ( windows -> cmd). : ttf2pt1 -A font.ttf font , ttf2pt1 C:\ , times.ttf C:\CyrFonts, : c:\ttf2pt1 -A c:\CyrFonts\times.ttf times c:\ttf2pt1 , -A , AFM,c:\CyrFonts\times.ttf TrueType , , times . ,AFM .

    . -PHP. FPDF . font/makefont/ . . (, mf.php) : require, . , font, makefont/makefont.php. MakeFont() : MakeFont(string fontf i le , stringafmfile [ , string enc [ , array patch [,string type]]]) fontfile TTF PFB ,afmfile AFM , enc ( cp1252), patch type ( True Type). :

    cp1250 (Central Europe) cp1251 (Cyrillic) cp1252 (Western Europe) cp1253 (Greek) cp1257 (Baltic) ISO-8859-1 (Western Europe) ISO-8859-2 (Central Europe) ISO-8859-4 (Baltic)

    ISO-8859-5 (Cyrillic)

  • 47

    FPDF ______________________________________________

    ISO-8859-7 (Greek) ISO-8859-15 (Western Europe) ISO-8859-16 (Central Europe) KOI8-R (Cyrillic)

    ( 0 255) . Windows cp1251. cp Windows, Linux ISO. mf.php . php. , ? times.ttf, times.afm times.php. (times.ttf times.php) . font, . , , . FPDF_FONTPATH PHP : define('FPDF_FONTPATH', 'font/ '); web PDF. 4. FPDF -, - . :

    : , , ;

    , , ;

    . . , . . , CSV, . xls , , (, HTML). PDF . FPDF. price.php, PDF ( 6). fpdf.php ( ) font (. ). price.php FPDF . ,

  • 48

    FPDF ______________________________________________

    (headers), , HTML . (, , ) FPDF: cell() image(). cell() ( ) , . : Cell(f loat w [ , f loat h [ , string txt [ ,mixed border [ , int ln [ , string align [,int f i l l [ , mixed l ink]]]]]]]) image() JPG PNG. : Image(string f i le , f loat x , f loat y , f loatw [, f loat h [ , string type [, mixedl ink]]]) , , , . : . TimesNew Roman ( ) FPDF , , . AddFont().

    . ( $name). (B Bold, I Italic BI IB). , . B I ( Times New Roman timesI.ttf timesBd.ttf). ( ). . SetFont(). , AddFont() . SetFont() : SetFont(string family [, string style [ ,f loat s ize]]) - . , , , FPDF . , FPDF . price.class.php, FPDF.

  • 49

    FPDF ______________________________________________

    , , 1.

    price.php ( 2):

    1

    2

  • 50

    FPDF ______________________________________________

    FPDF. , , Output(), . : Open(), AddPage(), Cell() , , . adobe acrobat 5.0, price.php price.pdf (Internet Explorer) doc.pdf (Opera). , .PDF. 5. . FPDF. , CSV . , - : , . , : ;15.00;13.45 ;14.00;12.30 Nemiroff, 1 .;100.00;89.45 price.csv. , - .

    ( , ,), ( ). , (). Price ( ): $header = array(""," ."," ."); Price ( FPDF) LoadData() ImprovedTable(). CSV $data, . LoadData() Price. price.class.php. ImprovedTable().

    function LoadData($file) { / / $lines=file($file); $data=array(); / / . foreach($lines as $line) $data[]=explode('; ' ,chop($line)); / / return $data; }

  • 51

    FPDF ______________________________________________

    :

    Price., , . ( 3). . , . . , ,, . (footer) . Footer() Price. , Footer() Header() FPDF AddPage() Close(). , , Footer() Header() . Price() :

    function ImprovedTable($header,$data) { / / $w=array(100,40,40); / / for($i=0;$iCell($w[$i],7,$header[$i],1,0, 'C') ; $this->Ln(); / / / / $this-> SetFont( 'TimesNewRomanPSMT', ' ' ,8); foreach($data as $row) { /* Cell() , $w, , ,LRBT (Left , Right , Bottom,Top). ( R) */

    / / $this->Cell($w[0],6,$row[0], 'LRBT'); / / $this-> Cell($w[1],6,number_format($row[1]) , 'LRBT',0, 'R') ; / / $this-> Cell($w[2],6,number_format($row[2]) , 'LRBT',0, 'R') ; / / $this->Ln(); } / /Closure l ine $this->Cell(array_sum($w),0, ' ' , 'T ') ; }

    function Footer() { / / 1.5 $this->SetY(-15); / /TimesNewRomanPSMT italic 8 $this->SetFont( 'TimesNewRomanPSMT', ' ',8); / / $this->Cell(0,10, ' ' .$this->PageNo(). ' /{nb}',0,0, 'C'); }

  • 52

    FPDF ______________________________________________

    AddPage(). (price.php) $price->AliasNbPages() $price->AddPage(). AliasNbPages([string al ias]) Footer() PageNo(), , {nb}, . , . 6. , ( adobe acrobat)

    . FPDF Output(). . FPDF : Output([string file [, boolean download]]) PDF ( PDF ). file . , . file , download , ( false) ( true ).

    3

  • 53

    FPDF ______________________________________________

    , Output() . Output() . Output(AlkoPrice.pdf, true). , , Output(AlkoPrice.pdf,false) Output(AlkoPrice.pdf), download false.

    . Zlib. (extension) . , , . , , !

  • 54

    : [[email protected]]

    1.

    1.1. ,

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

    - ; , . , , . . ,

    ( UNIX), , . . , . , , .

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

  • 55

    _________________________________________

    ( , , ). . . , . : , (, ), , . : ( ) , . ; . , . , , , , .

    . () - , ( , ), . : (, ), - ; . "" ( Write Ahead Log -WAL). , , , . , WAL, . . , - ( ). , , . , .

  • 56

    _________________________________________

    , , . , . , .

    - , . . : (SDL- Schema Definition Language) (DML - DataManipulation Language). SDL , , , .. , . DML , .. , , , . , , , . SQL(Structured Query Language). SQL , , "" (.. , SQL).

    , SQL SDL DML, .. . ( - ) , SQL -. () . SQL . , -, , .. SQL . SQL , ( ) . , , , , , . . , SQL. , SQL . , ,

  • 57

    _________________________________________

    . , . -, .

    1.2. : , ( ) -. . , (relations). , . , . . -. , , , . , . - , .

    1.3.

    , . - .

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

    1.4. , :

    Oracle Adabas-D Sybase FilePro MSQL Velocis MySQL Informix Solid

  • 58

    _________________________________________

    DBase ODBC Unix dbm PostgreSQL MS SQL

    , ODBC .

    1.5. : : - , Java, Java ,, -, .

    : , CGI, - .

    : API , ODBC JDBC.

    : , . . (multi-tiered) , . : : - (, ). : -, CGI API (, Apache, SQL, ). : (, MySQL).

    2. MySQL 2.1. MySQL

    PHP 10 ,

    MySQL. 90% MySQL, . MySQL , , . MySQL : UNIX. Windows NT Windows 95/98. MySQL : -MySQL , . MySQL

    API - MySQL , ,PERL, PHP

    - . , , . ( )

    , .

    , MySQL : SELECT - SELECT-, SELECT-. ,

  • 59

    _________________________________________

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

    - SQL, , . - ,

    - , () . MySQL , ,

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

    , , MySQL , . 2.2. MySQL

    MySQL

    , . UNIX , Windows - . , MySQL UNIX , Windows - .

    MySQL, , MySQL. , MySQL : mysql test. test , mysql (. 1).

    Mysql

    mysql. : MySQL , , SQL-. . 2.

  • 60

    _________________________________________

    mysqladmin,

    ( ) SQL-.

    columns_priv MySQL

    db func MySQL,

    host , tables priv

    MySQLuser

    1

    . help \h ? \? helpclear \c connect \r ()

    .

    ego \G () MySQL .

    exit \q . quit

    go \R () MySQL notee \t . print \P () . .. hash \# () source \. SQL .

    status \s tee \T .

    .

    use \u .

    2

  • 61

    _________________________________________

    3. SQL

    SQL . SQL , SQL, , . SQL SQL , . SQL. MySQL. 3.1. , , SQL, .

    CREATE . , . : CREATE DATABASE __

    CREATE TABLE:

    CREATE TABLE __

    (_)

    ( ) :

    :

    TYNYINT DATE SMALLINT TIME MEDIUMINT TIME STAMP INT INTEGE

    DATETIME TINYBLOB

    BIGINT BLOB REAL MEDIUMBLOB DOUBLE LONGBLOB FLOAT TINYTEXT DECIMAL TEXT NUMERIC LONGTEXT CHAR ENUM VARCHAR SET

    DROP CREATE, DROP DATABASE. DROP TABLE, DROP INDEX DROP FUNCTION. DROP DATABASE DROP TABLE. ( , ) : DROP DATABASE [IF EXISTS] : DROP TABLE [IP EXISTS] _ . , document author :

    DROP TABLE document, author 3.2. , .

    SQL, , .

  • 62

    _________________________________________

    INSERT INSERT . :INSERT [INTO] _ (_) VALUES (_3)

    , - . INTO . INSERT:

    INSERT INTO author (id, fullname, email)

    VALUES ('jOOl', 'John Writer', '[email protected]')

    REPLACE REPLACE, MySQL, INSERT, . , , , . REPLACE [INTO] _ (_) VALUES (_)

    UPDATE UPDATE. : UPDATE _ SET __1=_1, __2=_2 ,... [WHERE _]

    WHERE , . UPDATE:

    UPDATE documents SET title='Table of Contents', Comment='Fixed typo in the title' WHERE id=231

    id, 231, , .

    DELETE INSERT REPLACE. DELETE , . WHERE, , , . : DELETE FROM _ [WHERE _]

    DELETE. , 1 1999 :

    DELETE FROM documentsWHERE published < 4990-01-01'

    3.3. , SELECT Web- MySQL. : SELECT [DISTINCT]

    _ FROM _ [WHERE _] [GROUP BY _] [HAVING where_definition] [ORDER BY _ |

    [ASC | DESC]] [LIMIT [] _] [PROCEDURE _]

  • 63

    _________________________________________

    , , HAVING , ORDER BY LIMIT, PROCEDURE. SELECT , : SELECT SQRT((144 % 5) - 1) : DISTINCT .

    FROM , . M O I \ I , , , .

    WHERE , , . , Smith: SELECT DISTINCT

    document.title, author.fullname FROM document, author WHERE author.fullname LIKE "% Smith"

    LIKE , true, , false . -: '%',

    , '_', . GROUP BY . . , CLERKS : SELECT AVG(age), deptno FROM staff WHERE job='CLERK' GROUP BY deptno

    HAVING , , WHERE. , HAVING , , , GROUPBY. , , , 30 , : SELECT AVG(age) FROM staff WHERE job='CLERK' GROUP BY depno HAVING AVG(age)>=30

    ORDER BY . ASC ( ) DESC. , : SELECT id, title, published FROM document WHERE title LIKE %%' ORDER BY published

    LIMIT , SELECT. .

  • 64

    _________________________________________

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

    SELECT titles, published FROM document LIMIT 10

    10 ( 11-20):

    SELECT titles, published FROM document LIMIT 10, 10 PROCEDURE MySQL C++ . MySQL.

    3.4. MySQL . mysql : MySQL , , SQL-. , , SQL- (;) go (\g). :

    mysql> CREATE DATABASE accounts \g

    mysqladmin, ( ) SQL-. . Web,

    , SQL- () .

    Windows- MySQL- DB Tools, MySQL, DB- .

    MySQL- phpMyAdmin. Apache-. :

    , ,

    ,

    SQL-,

    ()

    (dumps)

    CSV-

    , 38

    phpMyAdmin , Apache. confis.inc.Dhn. 3:

  • 65

    _________________________________________

    phpMyAdmin Documentation.html, phpMyAdmin.

    3. Web- 3.1. . , , .

    . : - , , include() require().

    - SQL- PHP-, (.).

    ScfgPmaAbsoluteUri strin

    g URL, phpMyAdmin

    ScfgServers array MySQL. phpMyAdmin MySQL. , , : cfgServers[l]['host'], cfgServers[I]['host'] ...

    $cfgServers[n] ['host'] string

    n- MySQL . , "localhost"

    ScfgServers [n] ['port'] string

    MySQL n-

    $cfgServers[n] ['connect type']

    string

    . "top" "socket"

    $cfgServers[n]['auth_type']

    string

    . "http", "cookie" "config"

    $cfgServers[n]['user'| string

    , MySQL. "http" "cookie"

    ScfgServers [n] ['password']

    string

    , MySQL. "http" "cookie"

    ScfgServerDefault integer

    (), phpMyAdmin

    3

  • 66

    _________________________________________

    , SQL-.

    , . 3.2. MySQL mysql_connect MySQL. int mysql_connect (string [hostname [-.port} [ : /path_to_socket]] , string [username], string [password]);

    4 ; : - , - false . , MySQL.

    ( - MySQL) mysql_close .

    Mysql_close MySQL . int mysql_close(int [link-identifier] ) ;

    link identifier . : mysql_close true false .

    mysql_select_db . int mysql_select_db(string database name, int [link identifier]);

    hostname ,

    . ,

    "localhost"

    .port , . , , MySQL

    ":3306"

    ./path to socket

    Unix,

    ":/tmp/mysql.sock"

    username ,

    ,

    - password ; ,

    4

  • 67

    _________________________________________

    database name ,

    link-identifier , . : , . , , mysq_connect , .

    database ___ name , linkidentfier -. true false . SQL, MySQL, .

    mysql_query SQL MySQL : int mysql_query(string query, int [link identifier]);

    query SQL, MySQL link-identifier , . : - , . , , mysql_connect , . query , linkidentifier- .

    ( ) false . SQL MySQL.

    mysql_list_dbs

    , MySQL. int mysql_list_dbs(int [link identifier]) ;

    link-identifier , . : - , . , , mysql_connect , . linkidentifier . , false. mysql_tablename().

    mysql_list_tables MySQL. int mysql_list_tables(string database, int [link_identifier]);

    database name , . link-identifier , .

  • 68

    _________________________________________

    : , . , , mysql_connect , . database , linkidentifier - . , false. mysql_tablename().

    mysql_num_rows ( SQL). int mysql_num_rows(int result_identifier);

    result_identifier , mysql_ db_query, mysql_query, mysql_l is t_tables , mysql_l i s t _ dbs

    result identifier . , SELECT.

    mysql_table_name / :

    result_identifier , mysql_db_query, mysql_query, mysql_list_ tables, mysql_list_dbs.

    i result_ identifier. : resultidentifier i- .

    / i .

    mysql_num_fields . int mysql_num_fields(int resul_identifier);

    result_identifier , mysql_db_query, mysql_query, mysql_list_ tables, mysql_list_dbs mysql_query, mysql_list_dbs

    result_identifier . resultidentifier. mysql_field_name . string mysql_field_name (int result_dentfer, int field_lndex);

    result_identifier , mysql_db_query, mysql_query, mysql_list_ tables, mysql_list_dbs field_index

    result_identifier fieldindex . fieldindex resultidentifier.

    mysql_field_type string mysql_field_type (int result_identfier, int field_index);

    result_identifier , Mysql_db_query,

  • 69

    _________________________________________

    mysql_query, mysql_list_ tables,mysql_list_dbs

    field_index

    result_identifier field_index . fieldindex resultidentifier.

    mysql_fetch_row . array mysql_fetch_row(int result_identlfier);

    result_identifier , mysql_db_query, mysql_query, mysql_list_tables, mysql_list_dbs

    result_identifier . ( ) false, . mysql_fetch_row() result identifier, mysql_fetch_row() . mysqldataseek

    mysql_fetch_array . array mysql_fetch_array(int result_identifier, INT [result_type]);

    result_identifier , mysql_db_query,mysql_query, mysql_list_tables,mysql_list_dbs result_type , ()

    result_identifier . result_typc :

    MYSQLJMUM: ( mysql_fetch_row ());

    MYSQL ASSOC: ;

    MYSQL BOTH: , .

    result_type , MYSQL BOTH. mysql_fetch_array() , , false, . mysql_fetch_row(), . , mysql_fetch_array() ; . , , , .

    mysql_result . mixed mysql_result(int result_identifier, int row, mixed [field]);

  • 70

    _________________________________________

    result_identifier , mysql_db_query,mysql_query, mysql_list_tables,mysql_list_dbs

    row , field ,

    result_identifier row , a field - . row field result_identifier. field , table.column_name. field , .

    ! :

    , PHP, , . - PHP-Specialist - www.specialist.ru/?public=154398. : http://phpru.com, , php. , ...

    [[email protected]]. Maxim Matyukhin. . [nw; [email protected]]

    . ,

    , PHP [Tony2001], tony2001.phpclub.net

    [young] [Lenka] Maxim Matyukhin http://www.phpclub.ru [ PHP

    ]

    grafit44 - web-, http://grafit44.by.ru , [email protected]