961

Click here to load reader

Максим Кузнецов PHP5 практика разработки web-сайтов

Embed Size (px)

Citation preview

  • WEB-

    -

    -

    2005

  • 681.3.068+800.925 32.973.26-018.1

    89

    . ., . ., . .

    89 5. Web-. .: -,2005. 960 : .

    ISBN 5-94157-552-1

    5 , - Web-. MySQL, Web-, ,Flash PDF-. , , ,

    , ,

    FTP-, . - , HTML , Web-. - Web-,

    Web-.

    Web-

    681.3.068+800.92 5 32.973.26-018.1

    :

    .

    .

    .

    02429 24.07.00. 25.07.05. 70100'/,

    . . . . . 77,4.. 4000 . 1181

    "-", 194354, -, . , 5.- Ns 77.99.02.953..006421.11.04

    11.11,2004 . .

    " ""

    199034, -, 9 , 12

    I S B N 5-94157-552-1 . ., . ., . ., 2005 , "-", 2005

  • 1 1 2 3

    I. 5 5

    1. Web- Apache 71.1. Web- Apache 2.0.0 7

    1.1.1. Windows 71.1.2. Apache 131.1.3. Linux 16

    1.2. Web- Apache 2.0.0 191.2.1. Apache 191.2.2. 5 23

    1.3. PHP.INI 261.3.1. 261.3.2. 281.3.3. 281.3.4. 301.3.5. 311.3.6. 321.3.7. 321.3.8. 331.3.9. 33

    2. MySQL 392.1. MySQL 39

    2.1.1. MySQL Windows 402.1.2. MySQL Linux 43

    2.2. SQL- 442.2.1. 452.2.2. 462.2.3. 482.2.4. 482.2.5. MySQL 49

  • IV

    2.2.6. (SQL) 502.2.7. 772.2.8. 80

    2.3. MySQL 812.3.1. MySQL 812.3.2. MySQL 92

    2.4. phpMyAdmin 1082.4.1. phpMyAdmin 1092.4.2. phpMyAdmin 1152.4.3. phpMyAdmin 1242.4.4. 1312.4.5. 1352.4.6. 140

    3. HTTP 1433.1. HTTP- 1433.2. 147

    3.2.1. session_cache_limiter session_cache_expire 1503.3. HTTP- 152

    3.3.1. Accept 1523.3.2. Accept-Charset 1533.3.3. Accept-Language 1533.3.4. Allow 1543.3.5. Connection 1543.3.6. Date 1543.3.7. Expires 1543.3.8. From 1543.3.9. Last-Modified 1553.3.10. Location 1553.3.11. Referer 155

    3.4. : HTTP- 1553.5. : HTTP- 156

    4. "" 1584.1. JavaScript 158

    4.1.1. JavaScript 1584.2. , cookies? 1604.3. 1624.4. IP- 1644.5. 1684.6. 1704.7. 1704.8. ( ) 1714.9. 1764.10. 181

  • V

    4.11. 2024.11.1. 2074.11.2. CSS: 2084.11.3. 2104.11.4. 2124.11.5. 212

    5. 2155.1. , 215

    5.1.1. 2165.1.2. 2175.1.3. HTML- 218

    5.2. 2205.3. 224

    5.3.1. 2245.3.2. 226

    5.4. , cookie 2275.4.1. cookie 2285.4.2. cookie 229

    5.5. 2305.6. 233

    5.6.1. display_errors 2335.6.2. error-^reporting 2335.6.3. variablesjorder 2335.6.4. openbasedir 2345.6.5. disable ^ Junctions 2345.6.6. a/low_url_fopen 2345.6.7. register_globals 235

    5.7. MySQL 236

    II. 241

    6. 243

    7. 2497.1. CMS 251

    7.1.1. (CMS) 2517.1.2. 2517.1.3. 252

    7.2. CMS 2547.2.1. 2547.2.2. 2577.2.3. 259

    7.3. 266

  • VI

    8. 3338.1. 3358.2. 3368.3. " " 3418.4. - 377

    8.4.1. 3788.5. 384

    9. 3949.1. MySQL 3949.2. CMS 396

    10. "" 40310.1. 40410.2. 40510.3. 410

    11. "" " " 43011.1. 43011.2. 43211.3. 43711.4. 45311.5. 459

    12. 48112.1. 481

    12.1.1. 48312.2. 486

    13. 51113.1. 511

    13.1.1. 51213.1.2. SMTP, POP IMAP 51413.1.3. 519

    13.2. 52213.2.1. mail 52213.2.2. SMTP- 529

    13.3. 53213.3.1. ( Content-Type) 53313.3.2. ( Content-Transfer-Encoding) 53513.3.3. Content-Disposition 53613.3.4. , 536

  • VII

    14. 54314.1. PowerCounter 54314.2. PowerCounter 556

    I II . WEB- 617

    15. 61915.1. 62015.2. 622

    16. - 633

    17. 66117.1. 66217.2. 664

    17.2.1. 66917.2.2. 67217.2.3. 677

    18. 67818.1. 67818.2. 701

    IV. 5 711

    19. 71319.1. 714

    20. "" 72320.1. 723.20.2. 73020.3. 787

    21. 80921.1. 809

    21.1.1. 80921.1.2. 81121.1.3. 81221.1.4. 81321.1.5. 81321.1.6. 815

  • VIII

    21.2. 81621.2.1. 81821.2.2. 83321.2.3. 83821.2.4. 84421.2.5. 84621.2.6. 850

    V. 5 855

    22. . GDLib 85722.1. 857

    22.1.1. Windows 85822.2. 859

    22.2.1. gdjnfo 85922.2.2. exifjmagetype 86022.2.3. exif_read_data '. 86022.2.4. read_exif data 86222.2.5. exif thumbnail 86222.2.6. getimagesize 86222.2.7. imagesx 86322.2.8. imagesy 86322.2.9. image_type_to_mime_type 86322.2.10. imagetypes 864

    22.3. 86522.3.1. imagecreate 86522.3.2. imagecreatetruecolor 86522.3.3. imagecreatefromjpeg 86522.3.4. imageinterlace 86622.3.5. imagecreatefromgif. 86622.3.6. imagecreatefrompng 86722.3.7. imagesavealpha 86722.3.8. imagecreatefromgd 86722.3.9. imagecreatefromgd2 86822.3.10. imagecreatefromgd2part 86822.3.11. imagecreatefromstring . 86822.3.12. imagecreatefromwbmp 86822.3.13. imagecreatefromxbm 86922.3.14. imagecreatefromxpm 86922.3.15. imagedestroy 870

    22.4. 87022.4.1. imagecopy 87022.4.2. imagecopymerge 87022.4.3. imagecopymergegray 87022. imagecopyresampled 871

  • IX_

    22.4.5. irnagecopyresized 87222.4.6. imagerotate 87222.4.7. image/liter. 872

    22.5. 87222.5.1. imagejpeg 87222.5.2. imagegif. 87322.5.3. imagepng 87322.5.4. imagegd 87422.5.5. imagegd2 87422.5.6. imagexbm 87422.5.7'. imagewbmp 87422.5.8. image2wbmp 87522.5.9. jpeg2wbmp 87522.5.10. png2wbtnp 875

    22.6. 87622.6.1. imagefontheight 87622.6.2. imagefontwidth 87622.6.3. imageftbbox 87622.6.4. imagettfbbox 87722.6.5. imagepsbbox 87722.6.6. imagefttext 87822.6.7. imagettftext 87822.6.8. imagepstext 87922.6.9. imagepsloadfont 88022.6.10. imageloadfont 88022.6.11. imagepscopyfont 88122.6.12. imagepsfreefont 88122.6.13. imagepsencodefont 88122.6.14. imagepsextendfont 88222.6.15. imagepsslantfont 88222.6.16. imagechar 88222.6.17. imagecharup 88322.6.18. imagestring 88322.6.19. imagestringup 883

    22.7. 88422.7.1. imagealphablending 88422.7.2. imagesetthickness 88522.7.3. imagesetstyle 88522.7.4. imagesetbrush 88522.7.5. imagesettile... 88522.7'.6. imagelayerejfect 88622.7.7'. imageantialias 886

    22.8. 88622.8.1. imagesetpixel 88622.8.2. imageline 88622.8.3. imagedashedline 886

  • 22.8.4. imagerectangle 88722.8.5. imagepolygon 88722.8.6. imagearc 88722.8.7. imageellipse 88722.8.8. imagefilledrectangle 88722.8.9. imagefilledpolygon 88822.8.10. imagefilkdarc 88822.8.11. imagefilledellipse : 88922.8.12. image/ill 88922.8.13. imagefilltoborder 889

    22.9. 89122.9.1. imageistruecolor 89122.9.2. imagetniecolortopalette 89122.9.3. imagecolorallocate 89222.9.4. imagecolorallocatealpha 89222.9.5. imagecolordeallocate 89322.9.6. imagecolorat 89322.9.7. imagecolorsforindex 89322.9.8. imagecolorresolve 89322.9.9. imagecolorresolvealpha 89322.9.10. imagecolorexact 89322.9.11. imagecolorexactalpha 89422.9.12. imagecolorclosest 89422.9.13. imagecolorclosestalpha 89422.9.14. imagecolorclosesthwb 89422.9.15. imagecolorset 89422.9.16. imagecolortransparent 89522.9.17. imagecolorstotal 89622.9.18. imagecolormatch 89622.9.19. imagepalettecopy 89622.9.20. imagegammacorred 896

    22.10. 89722.10.1. iptcembed 89722.10.2. iptcparse 897

    23. Flash. ming 89823.1. 898

    23.1.1. Windows 89823.1.2. UNIX- 899

    23.2. ming 90023.2.1. SWFMovie 90123.2.2. SWFShape 90323.2.3. SWFDisplayltem 90523.2.4. SWFGradient . 90923.2.5. SWFBitmap 90923.2.6. SWFFill 910

  • XI

    23.2.7. SWFMorph 91123.2.8. SWFText 91123.2.9. SWFFont 91223.2.10. SWFTextField 91323.2.11. SWFSprite 91523.2.12. SWFButton .....91523.2.13. SWFAction 917

    23.3. 91723.3.1. 91723.3.2. . SWFBitmap 91823.3.3. SWFMorph 92023.3.4. action script SWFAction SWFButton 921

    24. PDF-. ClibPDF 92424.1. 925

    24.1.1. Windows 92524.1.2. UNIX- 925

    24.2. PDF- 92624.2.1. cpdf_open 92624.2.2. cpdf_save_tojile 92624.2.3. cpdf_page_init 92624.2.4. cpdf_add_outline 92724.2.5. cpdf_begin_text 92824.2.6. cpdf_end_text 92824.2.7. cpdf_set_/ont 92824.2.8. cpdfjext 92924.2.9. cpdf_set_text_rendering 92924.2.10. cpdfmoveto 92924.2.11. cpdfjineto 93024.2.12. cpdf_stroke 93024.2.13. cpdf_ finalize 93024.2.14. cpdf_output_buffer 93024.2.15. cpdf_close 93024.2.16. 930

    24.3. ClibPDF 93324.3.1. cpdf_add_annotation 93324.3.2. cpdf_arc 93324.3.3. cpdf_circle 93424.3.4. cpdfjclip 93424.3.5. cpdf_closepath 93424.3.6. cpdf_closepathjill_stroke 93424.3.7. cpdf__closepath_stroke 93424.3.8. cpdf_continue_text 93524.3.9. cpdf_curveto 93524.3.10. cpdfjill 935

  • XII

    24.3.11. cpdf_fuuilize_page 93524.3.12. cpdf_global_set_document_limits 93524.3.13. cpdfjmportjpeg 93624.3.14. cpdf_place_inline_image 93624.3.15. cpdf_newpath 93624.3.16. cpdf_rect 93724.3.. cpdf_save 93724.3.18. cpdf_restore 93724.3.19. cpdf_rotate 93724.3.20. cpdf_rotate_text 93824.3.21. cpdf_scale 93824.3.22. cpdf_set_action_url 93824.3.23. cpdf_set_char_spacing 93824.3.24. cpdf_set_creator 93824.3.25. cpdf_set_current_page 93824.3.26. cpdf_set_horiz_scaling 93924.3.27. cpdf_set_keywords 93924.3.28. cpdfjset leading 93924.3.29. cpdf_set_page_animation 93924.3.30. cpdf_set_subject 94024.3.31. cpdf_set_text_matrix 94024.3.32. cpdf_set_text_pos 94024.3.33. cpdf_set_text_rise 94024.3.34. cpdf_set_title 94024.3.35. cpdf_set_word_spacing 94024.3.36. cpdf_setdash 94124.3.37. cpdf_setrgbcolor 94124.3.38. cpdf_setflat 94124.3.39. cpdf_show_xy 94124.3.40. cpdf_stringwidth 94124.3.41. cpdftranslate 941

    942

    . - 943

    944

  • , 2004 ., "-" " 5", 5. -,

    , , , -

    . , -

    ,

    . , , -

    , . ,

    , , , ,

    . , -

    , ,

    5 Web- .

    , , -

    HTML,

    Web- 5. - -

    Web-, . Web- , -

    , -

    .

    , , Web- Web- . -

    , , -

    Web- Apache MySQL.

    , Flash PDF-.

    CD, Web-, Web- MySQL phpMyAdmin,

  • _

    Web- Apache, MySQL PHP 5.0.0. , , Web-, .

    Web- JT- SoftTime, , (http://www.softtime.ru/forum/), - . -

    ,

    Web-.

    , 24 , , -. 5 . , -

    Web- 5. 1 5, Web- Apache MySQL. Apache (- php.ini). 2 MySQL: MySQL, SQL-, MySQL, , Web- MySQL phpMyAdmin. 3 HTTP-. 4 " " . ,

    .

    5, - .

    -

    Web-, ,

    : , , , -

    , , , -

    (" "). , -

    , 6.

  • 3

    7 -: .

    8 . 9 . "" 10. 11 "" " ". 12 . 13 , , , -

    , , -

    .

    14 .

    Web-. 15 .

    16 FTP-. 17 - Web-. 18 . , 1921, - -

    .

    , , , , -

    .

    22 5 GD. Flash ( Ming) 23. 24 PDF- - ClibPDF.

    "--

    ", .

  • 4

    ,

    " 5", "--" 2004 . - .

    [email protected], http://www.softtime.ru/. , ,

    http://www.softtime.ru/forum/.

  • I

    5

  • 1

    Web- Apache1.1. Web- Apache 2.0.0 Web- Apache 2.0.0 - Windows Linux. , , - ,

    Apache http://www.apache.org.

    1.1.1. Windows Web- Apache Windows , Windows - TCP/IP. Windows 2000 Windows XP - .

    , -

    .

    ^ 7 ^ [ , Web- Apache - Windows, Apache 2.0.0 - Windows. POSIX, - Apache Windows.

    Apache Windows , - . -

    , Apache. - ,

    , .

    Microsoft Visual Studio. - , .

  • I. 5

    ^

    Apache -, , msi '___\/132_*_.1.

    httpd_BepcnH_win32_*_.msi Microsoft Installer (. 1.1).

    The Installation Wizard will allow you to modify, repair, or removeApache HTTP Server 2.0.48. To continue, click Next.

    Welcome to the Installation Wizard forApache HTTP Server 2.0.48

    Next> Cancel

    . 1.1. Windows Installer

    : Far, NortonCommander . ., .

    Next, , . 1.2. -

    Apache (. 1.3). - , . 1.4, : , -

    . , -

  • 1. Web- Apache

    locaihost (. . 1.4). , -

    (80 8080).

    Apache HTTP Server 2.0 - Installation Wizard

    License Agreement

    Please read the following license agreement carefully.

    The Apache Software License, Version 1.1

    opyright (c) 2001 The Apache Software Foundation. All rights reserved.

    Redistribution and use in source and binary forms, with or without modification, arepermitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this list ofconditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright notice, this list ofconditions and the following disclaimer in the documentation and/or other materials ,.!

  • 10 I. 5

    i f f Apache HTTP Server 2.0 - Installation WizardRead This First

    Read this Before Running Apache on Windows.

    Apache HTTP Server

    What is it?The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant web server. .Originally designed as a replacement for the NCSA HTTP Server, it has grown to be the :most popular web server on the Internet. As a project of the Apache SoftwareFoundation, the developers aim to collaboratively develop and maintain a robust,commercial-grade, standards-based server with freely available source code.

    The Latest VersionDetails of the latest version can be found on the Apache HTTP server project pageunder;

    http://httpd.apache.org/

    DocumentationThe documentation available as of the date of this release is included in HTML format in ! > 1

    !iv

    Cancel

    . 1.. Apache 2.0

    # Apache HTTP Server 2.0 - Installation WizardServer I n f o r m a t i o n

    Please enter your server's information.

    Network Domain (e.g. sotnenet.com)jlocalhost

    - ' ; . ' : . : ;

    Server Name (e.g; www.somenet.com):jlocalhost

    Administrator's Email Address (e.g. webmastersomenet.com):

    Install Apache HTTP Server 2.0 programs and shortcuts for:

    (* for All Users, on Port 80, as a Service Recommended. only for the Current User, on Port 8080, when started Manually.

  • 1. Web- Apache 11

    \ Apache HTTP Seruer 2.0 - Installation Wizard

    Setup Type

    Choose the setup type that best suits your needs.

    Please select a setup type.

    Cancel

    . 1.5.

    ] # Apache HTTP Server 2.0 - Installation WizardDestination Folder

    Click Change to install to a different folder

    G Install Apache HTTP Server 2,0 to the folder:CiVrogram Files\4pache Group\ Change...

    Cancel

    . 1.6. Apache

  • 12 I. 5

    \ Apache HTTP Server 2.0 - Installation WizardReady to Install the Program

    The wizard is ready to begin installation.

    Click Install to begin the installation.

    If you want to review or change any of your installation settings, click Back, Click Cancel to exitthe wizard.

  • 1. Web- Apache 13

    Apache

    . 1.9. ApacheMonitor

    ( ^ ApacheMonitor , -. , bin - Apache.

    , http://localhost ( ); - , . 1.10.

    If you can see tins, it means that the iustnllntion of the Apache web server software on this system was successful You maynow add content to this directory anil replace this page

    Seeing this instead of the website you expected?This pa^e is here because the site administrator has changed the configuration of tins web server, plense ont;ct the personresponsible for maintaining this server with questions. The Apache Software Foundation, which wrote the web seiversoftware this rite administrator is using, has nothing to do with maintaining this site mid cannot help resolve configurationissues.

    The Apache documentation has been included with this distribution.

    You are free to use the image below on an Apache-powered web server. Thanks for using Apache!

    !=/>>. *-

    . 1.10. Web- Apache

    1.1.2. Apache Windows Apache : ApacheMonitor; Windows; ; .

  • 14 I. 5

    Apache ApacheMonitor Web- Apache ApacheMonitor - . -

    , 1.11, Start, Stop Restart - , .

    Apache Service Monitor

    Start

    Setvices

    Connect

    \pache/2.0.49 (Win32)

    . 1.11. Apache

    Apache Windows , Apache - , 80 (. . 1.4), Apache Windows. | | | | Services ApacheMonitor. , . 1.12, Apache2. - , .

    Windows .

    (. 1.12) (. 1.13), .

  • 1. Web- Apache 15

    **

    % (; I ()

    Apache2

    ' [ | | _*

    :Apache/2.0.48 (Win32)

    %-%DNS-iviHeHT*$}HDD Temperat.,.^Machine Debug...%M5 Software Sh,..*&>NetMeeting Re.,.feNVIDIA Driver...^Office Source E...4Plug and Play*&QoSRSVP%SplDer Guard f...

    < i I i \,

    ^Windows Audio^Windows Installer

  • 16 I. 5

    Apache , Apache . : | | Apache HTTPServer | Control Apache Server. , Start, Stop Restart.

    Apache , Apache - :

    Apache -k s t a r t (); Apache - r e s t a r t (); Apache -k stop Apache - shutdown ().

    bin Apache (C:\ProgramFiles\Apache Group\Apache2\bin\).

    ( ) - Apache., Apache -k i n s t a l l Apache - u n i n s t a l l - 2.

    ,

    Apache -help Apache.

    Apache - t Apache . -

    Syntax . ,

    , :

    Syntax error on line 57 of :/Program Files/Apache Group/Apache2/conf/httpd.conf:ServerRoot takes one argument, Common directory of server-related files

    1.1.3. LinuxWeb- Apache Linux, . -

    , Apache, -

  • 1. Web- Apache 17

    , Apache :

    tar -xzf apache_x....tar.gz

    ( ) Apache , root.

    configure, , .

    , -

    prefix, .

    1.1 , : /usr/local/apache/, SS1 CGI-.

    [ 1.1. configure# cd apache_x...# ./configure prefix=/usr/local/apache/\ disable-include\disable-cgi

    configure . 1.1. , , , -

    prefix -/ , , - 1.1.

    1.1. configure

    pref ics=pr - pr=/usr/local/apache

    b i n d i r = d i r dir

    s b i n d i r = d i r dir

    l i b e x e c d i r = d i r dir

    datadir=dir - , - dir

  • 18 I. 5

    1.1 ()

    infodir=dir

    withport=port

    enable-debug

    enable-file-cache

    enable-echo

    enable-cache

    disable-include

    disable-http

    disable-mime

    disable-dir

    enable-headers

    enable-tls

    enable-cgid

    disable-cgi

    i n f o dir

    p o r t , -

    -

    SSI-

    HTTP-

    -

    MIME

    HTTP-

    TLS/SSL

    CGI-

    CGI-

    :

    # make# make i n s t a l l

    make , makei n s t a l l , - prefix (. 1.1). Apache apachecti. , s t a r t :

    # /usr/local/apache/bin/apachectl start

    stop r e s t a r t - .

  • 1. Web- Apache 19

    , ( - Window) ( ):$ lynx http://localhost/, Apache, :$ ps aux | grep httpd , -

    httpd. Apache - . RedHat Linux (Fedora Core) - /etc/rc.d/init.d/ apache:# /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache# chmod 755 /etc/rc.d/init.d/apache

    ,

    . /etc/rc.d/rc3.d/ # In -s ../init.d/apache S99apache# In -s ../init.d/apache KOlapache

    rc3.d, -

    .

    ( ) Apache ( , ). Apache , - , , rc5.d 5 (- , Windows).

    RedHat (Fedora Core) , ntsysv.

    1.2. Web- Apache 2.0.01.2.1. Apache Apache HTML- -, text /html mime.types , PHP- (php, phtml):text/html html htm shtml shtm php phtml

  • 20 I. 5

    Apache httpd.conf, - C:\Program Files\Apache Group\Apache2\conf\. :

    1. ServerAdmin - . :

    ServerAdmin [email protected]

    -

    .

    2. serverName ( ) , - :

    ServerName Maks

    DocumentRoot , ,

    (HTML- -):DocumentRoot d:\main\html

    ,

    .

    3. , - , :

    Options Indexes FollowSymLinksAllowOverride None

    4. options AllowOverride Web-, . . DocumentRoot. - DocumentRoot, :

    Options Indexes FollowSymLinksAllowOverride NoneOrder allow,denyAllow from all

    options FollowSymLinks, - Apache DocumentRoot. ,

    .

  • 1. Web- Apache 21

    indexes , . None AllowOverride , - .

    ( ^ AccessFileName - htaccess.

    5. allow deny. , - allow deny, . Allow from a l l , .

    6. , - ,

    userDir ,:

    UserDir "d:\main\html\users"

    http://www.url.ru/~user, www.url.ru , a user .

    7. , -

    (, http://localhost/dort/), Drectorylndex:Directorylndex index.html index.phtml index.php

    ( " ^ ,

    D i r e c t o r y l n d e x . To dort index.php index.html, http://Iocalhost/dort/ - index.html.

    index.*, -.

    8. CGI- , , scriptAiias ScriptAiias /cgi-bin/ "cgidir".

    2 3. 81

  • 22 I. 5

    :

    ScriptAlias /cgi-bin/ "d:\main\cgi-bin"

    , . CGI- ( , ). :

    AllowOverride NoneOptions ExecCGI

    AddHandier:AddHandler cgi-script .bat .exe

    Apache exe bat CGI-.

    9. AddHandler server-parsed -:

    AddHandler server-parsed .shtml

    Apache . Apache . D:/main/html index.html, HTML-. - http://Iocalhost/index.html - -

    .

    Apache - , httpd.conf. ,

    NamevirtuaiHost :NameVirtualHost 127.0.0.1:80

    , , ( - ):# ServerAdmin webmasterShost.some_domain.com# , DocumentRoot d:/main/first/# ( )ServerName maks# ServerAlias localhost

  • 1. Web- Apache 23

    # , log-; logs # ApacheErrorLog logs/maks-error.logCustomLog logs/maks-access.log common

    . , , -

    . ,

    . , . .

    http.conf , , Apache.

    1.2.2. 5Windows (http://wAvw.php.net) 5.0.0. 5.0.0 , -

    .

    C:\php - . -

    php.ini-dist php.ini - Windows. php.ini extension_dir , :

    extension_dir = "c:\php"

    doc_root DocumentRoot Web-. :

    doc_root = "d:\main\http"

    ,

    extension = php*.dll

    , -

    error_reporting php.ini. , - .

    . 1.2.

  • 24 I. 5

    1.2.

    E_ERROR

    E_WARNING

    E_PARSE

    NOTICE

    E_CORE_ERROR

    E_CORE_WARNING

    E_COMPILE_ERROR

    E_COMPILE_WARNING

    E_USER_ERROR

    E__USER_WARNING

    E_USER_NOTICE

    E ALL

    ( ) ( )

    ( , -

    ,

    )

    e r r o r r e p o r t i n g , - , ,

    error_reporting = E_ALL & ~E_NOTICE

    , .

    , ,

    5 , - .

    log-. Web- , - dispiay_errors:display_errors = On

    log- - log_errors:log_errors = On

    dispiay_errors iog_errors off log- -.

  • 1. Web- Apache 25_

    e r r o r l o g = syslog - Windows, | | - | | . Web- httpd.conf :

    AddType application/x-httpd-php phtml php

    Options ExecCGI

    Action application/x-httpd-php "c:\php\php-cgi.exe"

    Apache, phtml php. , , (C:/php), CGI-. Action PHP- php-cgi.php, - C:\php.

    5 PHP- Hephp.exe.aphp-cgi.exe.

    ,

    Apache. , -

    DocumentRoot, test.php, , :

    , http://localhost/test.php Hello, PHP !

    ( ) .

    ,

    php.ini Web- Apache. , - extension_dir: extension_dir = ":/php/ext".

    Linux 5 :# tar -xzf php-5.x.x.tar.gz

  • I. 5

    , -

    config.sh :./configure\with-apxs=/usr/local/apache/bin/apxs\with-mysql=/var/lib/mysql/

    ,

    . -

    with-apache --with-apxs, , - , -

    . ,

    Apache . config.sh :

    # chmod 755 config.sh

    :

    ./config.sh

    , -

    :

    makemake install

    . Linux Windows, php.ini /etc.

    1.3.PHP.INI php.ini, - . , -

    .

    1.3.1. engine = On

    (on) (off) Apache.short_open_tag = On

    (on) (off) -

  • 1. Web- Apache 27

    -

    .

    output_buffering = 40 9 6

    -

    . (outputbuf fering =On) , cookie . , , -

    .

    implicit_flush Off

    flush (, ) pr int echo HTML-. - ,

    , .

    allow_call_time_pass_reference = Off

    ,

    . 5 . -

    , 5 ( , ).safe_mode = Off

    (off) (on) .safe_mode_allowed_env_vars = _

    ,

    , _. -

    , ,

    .

    safe_mode_protected_env_vars = LD_LIBRARY_PATH

    ,

    , putenv. ,

    s a fe_mode_a11owed_env_va r s.disable_functions =

    , . -

    , -

    .

  • 28 I. 5

    disable_classes =

    -

    , .

    , .

    highlight.string = #DD0000highlight.comment = #FF8000highlight.keyword = #007700highlight.bg = #FFFFFFhighlight.default = #0000BBhighlight.html = #000000

    , -

    highlight_string() highlight_f i l e () .

    1.3.2. max_execution_time = 30

    ,

    30 .max_input_time = 60

    ,

    .

    memory_limit = 8

    , , -

    , 8 .

    1.3.3. error_reporting =

    err orrepor ting , . . ,

    | (OR): E_ALL ( ); > E_ERROR ( ); EWARNING ( -

    ); E_PARSE ( ); NOTICE ( , -

    ; , ,

    );

  • 1. Web- Apache 29

    E_CORE_ERROR ( ); E_CORE_WARNING ( ); E_COMPILE_ERROR ( ); E_COMPILE_WARNING ( ); E_USER_ERROR (, ); E_USER_WARNING (, ); E_USER_NOTICE (, ). , , ,

    ,

    error_reporting :error_reporting = E_ALL & ~E_NOTICE

    , -

    , :

    error_reporting = E_COMPILE_ERROR|E_ERROR|E__CORE_ERRORdisplay_errors = Off

    . -

    ,

    ( 5 ), dispiay_errors . .

    display_startup_errors = Off

    (off) (on) , - .

    log_errors = Off

    (off) (on) .

    log_errors_max_len = 1024

    .

    track_errors = Off

    (off) (on) - $php_errormsghtml_errors = Off

    (off) (on) HTML.error__log = filename

    filename.

  • 30 I. 5

    1.3.4.

    ( ^ t r a c k _ v a r s 4.0.3.

    variables_order = "EGPCS"

    GET, POST,cookie, Environment ( G, , , s). . 5 GPCS.

    ( ^ v a r i a b l e s _ o r d e r GP, , -

    POST GET. , cookie, .

    register_globals = Off

    (off) (on) - EGPCS- . - "" ,

    .

    ( ^ ) r e g i s t e r g l o b a l s - . ,

    PHP- ,

    ,

    90% . , -

    ( 4.3 - ), - , .

    ( , ,

    .)

    ( - , -

    , , -

    . -

    , .

  • 1. Web- Apache 31_

    register_long_arrays = Off

    , (on) (off) $HTTP_GET_VARS,$HTTP_POST_VARS . . , - $_GET, $_POST . .

    ( ^) (Off) , ,

    r e g i s t e r _ l o n g _ a r r a y s . -

    $HTTP_GET_VARS $_GET. - , , .

    post_max_size = 8

    ,

    POST.

    magic_quotes_gpc = Off

    (off) (on) - , GET, POST, Cookie.magic_quotes_runtime = Off

    (off) (on) - ('something1).auto_prepend_file =auto_append_file =

    , , -

    .

    default_mimetype = "text/html"

    ,

    Content-type. - text /html .

    1.3.5. ; UNIX: "/pathl:/path2";include_path = ".:/php/includes"

    ; Windows: "Ypathl;\path2";include_path = ".;:\php\includes"

    , PHP-.

  • 32 I. 5

    doc_root =

    -.

    extension_dir = "./"

    , -

    .

    enable_dl = On

    , (on) (off) - dl.

    d l , , SQLLite. Web- (IIS, Zeus) .

    1.3.6. file_uploads = On

    , (on) (off) .

    upload_tmp_dir =

    .

    upload_max_filesize = 2

    , .

    1.3.7. allow_url_fopen On

    , (on) (off) URL(http://, ftp://) .

    ( ^ .

    from=johnSdoe.com, .

    user_agent="PHP"

    , USERAGENT, .

    default_socket_timeout = 60

    , , .

  • 1. Web- Apache 33_

    1.3.8.

    extension :extension=modulename.extension

    , Windows :extension=msql.dll

    UNIX :extension=msql.so

    , . ,

    extension_dir.

    1.3.9. Syslogdefine_syslog_variables = Off

    , , (on) (off) - syslog, $LOG_PID, $LOG_CRON . . , -

    define__syslog_variables.

    mail functionSMTP = localhost

    Windows SMTP-.sendmail_from = admin@localhost

    Windows From .sendmail_path = \usr\sbin\sendmail -t -i

    UNIX - sendmail.

    Debuggerdebugger.enabled = Ondebugger.profiler_enabled = On

    , (on) (off) .

  • 34 I. 5

    JavaJava.class.path = . \php_java.jarJava.home = c:\jdkJava.library - c:\jdk\jre\bin\hotspot\jvm.dllJava.library.path = .\

    Java.uodbc.allow_jDersistent = On (on) (off) ODBC-.

    uodbc.check_persistent = On

    (on) (off) ODBC- .

    uodbc.max_persistent = -1

    , ODBC--. -1 , .uodbc.max_links = -1

    , , -

    ODBC-. -1 , .uodbc.defaultlrl = 4096

    LONG-.uodbc.defaultbinmode = 1

    , .

    passthru, i as is, 2 - .

    MySQLmysql.allow_persistent = On

    (on) (off) MySQL-.

    mysql.max_persistent = -1

    , MySQL-. -1 , .mysql.max_links = -1

    , , -

    MySQL-. -1 , .mysql.default_port =

    , ,

    mysqi_connect. mysqi_connect -

  • 1. Web- Apache 35

    $MYSQL_TCP__PORT mysqi-tcp /etc/services, MYSQL_PORT( ).

    ( ^ Windows MYSQL_PORT.

    mysql.default_socket =

    , MySQL. .

    mysql.default_host =

    ,

    mysql_connect().mysql.default_user =

    .

    -

    ,

    mysql_connect().mysql.default_password =

    , .

    -

    ,

    mysql_connect().

    ( ^ , -

    , ,

    echo c f g _ g e t _ v a r ( " m y s q l . d e f a u l t _ p a s s w o r d " ) .

    ( ) .

    php.ini , .

    bcmathbcmath.scale

    , bcmath-( ).

  • _56 I. 5

    Sessionsession.save_handler = files

    , , ( - ).session.save_path = /tmp

    ,

    ,

    .

    session.use_cookies = 1

    , , Cookies ( Cookies ).session.name = PHPSESSID

    , .

    session.auto_start = 0

    ,

    ( ).session.cookie_lifetime = 0

    Cookie . 0, Cookie .session. cookie_path = /

    /I-

    , ,

    Cookie.session.cookie_domain =

    Cookie ( setcookie).session.serialize_handler = php

    , . php .

    session.gc_probability = 1

    , ,

    , , " "

    , .

    session.gc_maxlifetime = 1440

    ,

    .

    session.referer_check =

    , , -Referer , .

  • 1. Web- Apache 37_

    session.cache_limiter = nocache

    , HTTP. : nocache, private, public.

    3.

    session.cache_expire = 180

    , ,

    .

    ,

    .

    session.use_trans_sid = 1

    , , -

    SID ( ). , - , Cookies .

    ( ) , -

    enable-trans-sid.

    session.hash_function = 0

    , - . 0 - MD5, 1 SHA-I.

    Assertionassert.active = On

    , , assert , -, .

    assert.warning = On

    , , -

    assert .assert.bail = Off

    , , (on) (off) assert .assert.callback = 0

    , , -

    assert (). - , . . .

  • I. 5

    Verisign Payflow Pro( -)pfpro.defaulthost = "test.signio.com"

    , URL- -.pfpro.defaultport = 443

    -.

    pfpro.defaulttimeout = 30

    - -.

    pfpro.proxyaddress =

    IP- - .pfpro.proxyport =

    - .

    pfpro.proxylogon -

    -.

    pfpro.proxypassword =

    -.

    Socketssockets.use_system_read = On

    , read .

  • 2

    MySQL Web- , -

    : , , ,

    . -

    SQL-. - , .

    ( 23 ) - Web-, . -

    Web-, . , ,

    ,

    Web- . ,

    ,

    . , Google, - , -

    . ,

    , .

    MySQL - - , , ,

    .

    MySQL , MySQL.

    2.1. MySQL MySQL , .

  • 40 I. 5

    ^

    -

    MySQL http://dev.mysql.com/doc/mysql/ru/index.html.

    MySQL Windows Linux. .

    2.1.1. MySQL Windows MySQL : , ;

    .

    MySQL , - http://www.mysql.com/downloads/. Windows NT/2000/XP -. ,

    setup.exe. - . MySQL C:/mysql., , .

    MySQL 3.23:38 Windows , , MySQL-Max. MySQL, -:

    mysqid ( ,

    ); mysqid-opt ( -

    ); mysqid-nt ( Windows NT/2000/XP

    ); mysqid-max ( -

    ); mysqld-max-nt ( , mysqld-max,

    ). my.ini : -

    (C:/nrysql C:/mysql/data);

  • 2. MySQL 41_

    mysqld, mysqld-max mysqld-max-nt;

    .

    MySQL - WinMySQLAdmin, (\mysql\bin\ winmysqladmin.exe), - .

    WinMySQLAdmin , .

    ,

    mysqld.

    WinMySQLAdmin , -

    MySQL, "" : , ,

    (. 2.1).

    ShutDovvn this Tool

    Start the Service

    Remove the Service

    Show

    M'.'.Tl.'

    Or Lee ^

    me

    > 3D V

    . 2 .1. WinMySQLAdmin

    Windows NT/2000/XP MySQL - , mysqld . WinMySQLAdmin Install the Service.

    WinMySQLAdmin MySQL , - my.cnf my.ini.

    ( ^ : my.cnf my.ini, MySQL my.ini, my.cnf.

    ( ) WinMySQLAdmin my.ini.

  • 42 I. 5

    [mysqid], basedir datadir:[mysqid]# set basedir to installation path, e.g., c:/mysqlbasedir - the_install_path# set datadir to location of data directory,# e.g., c:/mysql/data or d:/mydata/datadatadir = the_data_path :

    :\mysql\bin> mysqld-max standalone :

    :\mysql\bin> mysqladmin -u root shutdown

    mysqid ::\mysql\bin> mysqld-max-nt --install

    MySQL mysql.

    Web- MySQL (phpMyAdmin) . 2.4 .

    mysql - MySQL . - , .

    mysql -h host -u user -p , "Enterpassword".

    MySQL , mysqi:mysql>

    , mysql . MySQL . -

    , mysql. mysql , mysqi> QUIT:mysql> QUIT

  • 2. MySQL 43

    ,

    MySQL. , - e x t e n s i o n = p h p _ m y s q l . d l l php.ini Web- Apache. , - e x t e n s i o n d i r :extension_dir = ":/php/ext".

    2.1.2. MySQL Linux Linux MySQL. -

    RedHat Linux (Fedora Core). MySQL MySQL http://www.mysql.com/downloads/ RPM-: MySQL-server-VERSiON.i38 6.rpm ( MySQL); MySQL-ciient-VERSiON.i386.rpm (

    MySQL; ); MySQL-bench-vERSiON.i386.rpm ( ;

    Perl msql-mysql-modules); MySQL-devei-VERSiON.i386.rpm ( , -

    MySQL); MySQL-shared-VERSiON.i38 6.rpm (

    l ibmysqlc l ient . so*, - , MySQL);

    MySQL-VERSioN.src.rpm ( ).

    RPM, rpm -qpl MySQL-VERSION.i386.rpm

    , -

    root:rpm -ihv MySQL-server-VERSION.i38 6.rpm MySQL-client-VERSION.i386.rpm

    RPM /var/lib/mysql/ /etc/init.d/ .

    MySQL :

    rpm -Uhv MySQL-server-VERSION.i38 6.rpm MySQL-client-VERSION.i386.rpm

  • 44 I. 5

    MySQL Windows, Linux MySQL mysqld.

    RPM- - MySQL. MySQL, mysqld -, ,

    , ntsysv, -, .

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

    MySQL, - , . -

    , -

    SQL, . SQL - , , SQL, .

    ( ^) , SQL , -

    . ,

    ,

    , SQL. , ,

    .

    , MySQL , (), - . .

    , MySQL, : , . " " NULL, - .

    -

    ([ ]). , I N T [ () ] , , [ () ] , .

  • 2. MySQL 45

    2.2.1. .

    ,

    . 2.1.

    2.1.

    TINYINT[()]

    MEDIUMINT[

    INTI

    BIGINT [ ()

    FLOAT[(M,D)]

    1

    SMALLINT[(M)] 2

    3

    4

    8

    4

    D O U B L E [ ( M , D ) ] 8

    DECIMAL [ (, D) ] + 2

    -128 127 ( - 2 7 27-1)

    0 255 ( 0 28-1) -32 768 32767 ( - 2 1 5 215-1)

    0 65 535 ( 0 21 6-1) - 8 388 608 8 388 608 ( - 2 2 3 2 -1) 0 16 777 215 ( 0 224-1)-2 147 683 648 2 147 683 648 (-23 1 231-1) 0 4 294 967 295 ( 0 232-1) - 2 6 3 2 6 3 - 1

    0 2 6 4

    +/-1.175494351-39

    +/-3.402823466+38

    +/-2.2250738585072014-308

    +/-1.797693134862315+308

    ; D

    . 2.1, MySQL : TINYINT,SMALLINT, MEDIUMINT, INT, BIGINT. , .

    ,

    .

  • 46 I. 5

    ( ) I N T INTEGER.

    .

    UNSIGNED.

    .

    ( 1 255). , -

    .

    ( ^ ,

    mysql, , .

    MySQL :FLOAT, DOUBLE DECIMAL.

    ( ^ DOUBLE : PRECISION REAL. DECIMAL - NUMERIC.

    , , -

    , . -

    . 2.1 , D .

    , :

    , ,

    100, TINYINT. , -

    UNSIGNED .

    2.2.2. , -

    . 2.2. L , , L, .

  • 2.

    MySQL

    2.2.

    47

    .

    CHAR(M)

    YARCHAR(M)

    TINYBLOB, TINYTEXT

    BLOB, TEXT

    MEDIUMBLOB, MEDIUMTEXT

    LONGBLOB, LONGTEXT

    E N U M ( ' v a l u e l ' , ' v a l u e 2 ' , . . . :S E T ( ' v a l u e l ' , ' v a l u e 2 ' , . . . )

    M

    L+1

    1+1

    L+2

    L+3

    L+4

    1 2

    1, 2, 3, 4 8

    28-1

    21 6-1

    22 4-1

    23 2-1

    65 535

    64

    CHAR , VARCHAR, L. 1 255.

    , VARCHAR , , CHAR(M) . CHAR - .

    CHAR VARCHAR. - , MySQL -: ,

    CHAR VARCHAR.

    BLOB TEXT MySQL . , TEXT , BLOB .

    TEXT , BLOB , , , . .

    ENUM SET. - . -

    , ENUM - , SET ( ) -. , , E N U M ( ' 1 , ' ' ) ,

  • 48 I. 5

    : '1, ' \

    HTML-. SET, ENUM, , -

    , , .

    -

    HTML- . ENUM SET , .

    .

    ENUM 1. - 1 ( 256 ) 2 ( 257 65 536 ). SET , : 1 ( 1 8 -), 2 ( 9 16 ), 3 ( 17 24 ), 4 ( 25 32 ) 8 ( 33 64 ).

    2.2.3. MySQL 5 :DATE, DATETIME, TIME, TIMESTAMP YEAR (. 4.3).

    2.3.

    DATE

    TIME

    DATATIME

    TIMESTAMP[(M)]

    YEAR[(M)]

    3

    3

    8

    4

    1

    '1000-01-01' '9999-12-31'

    '-828:59:59' '828:59:59'

    '1000-01-01 00:00:00' '9999-12-3100:00:00'

    19700101000000 - 2037

    1 9 0 1 2 1 5 5 Y E A R ( 4 )

    1970 2069 YEAR (2)

    2.2.4. ,

    . ENUM SET

  • 2. MySQL 49_

    , -

    , -

    .

    . IP- I N T ( 4 ) . , -

    .

    , ,

    , .

    , ,

    , .

    ,

    .

    ( ) ,

    OPTIMIZE TABLE.

    2.2.5. MySQL MySQL :ISAM, MylSAM, MERGE, HEAP, BDB InnoDB.

    MySQL ISAM, - . -

    ISAM SQL. ISAM . MySQL, , .

    MylSAM, . - ISAM :

    ;

    , ;

    AUTO_INCREMENT;

    ;

    FULLTEXT.

  • 50 I. 5

    MERGE MyiSAM . -

    , .

    ,

    , MyiSAM. HEAP , .

    .

    BDB Berkeley DB, - Sleepycat. BDB : ;

    ;

    , -

    .

    innoDB , - MySQL. innoDB, Innobase Oy. :

    ;

    ;

    , ;

    , -

    .

    -

    , , .

    2.2.6. (SQL) SQL : , , -

    , . . -

    .

    ( , SQL 1992 ., , . ,

    -. -

  • 2. MySQL 51

    SQL, MySQL, .

    SQL.

    CREATE DATABASE :

    CREATE DATABASE [IF NOT EXISTS] db_name;

    db_name . forum, - mysqi ( 2.1).

    : : : ; : ; - ' " "

    ; 2.1.

    mysql> CREATE DATABASE forum;

    ( ^) MySQL mysql , - PHP- .

    I F NOT EXISTS , , ,

    . -

    SQL -. , forum , SHOW DATABASES ( 2.2), , .

    : 2.2. !

    mysql> SHOW DATABASES;

    ,

    forum (. 2.2).

    ( ^ ) SHOW MySQL, - SQL . , - SQL, - SHOW.

  • 52 I. 5

    I Database I

    authcountforumguestlocalmysqltest

    7 rons in set (0.00 sec). 2.2

    MySQL : t e s t mysql. ,

    MySQL.

    USE , MySQL, . -

    USE:USE db_name;

    dbname . forum ( 2.3).

    ! 2.3.

    mysql> CREATE DATABASE forum;Database changed;

    mysql , , :mysql forum.

    CREATE TABLE CREATE TABLE . - :

    CREATE TABLE table_name [(create_definit ion, . . . ) ] [ t a b l e _ o p t i o n s ]

  • 2. MySQL 53_

    table_name ; create_definition - , .

    t a b i e o p t i o n s , ,TYPE=MyISAM.

    forum, authors :

    (name), (passw), e-mail (email), Web- (uri), ICQ (icq), (about), , (photo), (time), ( l a s t t i m e ) , , - (themes), ,

    (statususer). id_author, .

    SQL-, , 2.4.

    ! 2.4. authors forum

    mysql> CREATE TABLE authors (mysql> id_author INT NOT NULL AUTO_INCREMENT,mysql> name TINYTEXT,mysql> passw TINYTEXT,mysql> email TINYTEXT,mysql> url TINYTEXT,mysql> icq TINYTEXT,mysql> about TINYTEXT,mysql> photo TINYTEXT,mysql> time DATETIME DEFAULT NULL,mysql> last_time DATETIME DEFAULT NULL,mysql> themes INT DEFAULT NULL,mysql> statususer INT DEFAULT NULL,mysql> PRIMARY KEY (id_author)mysql> ) TYPE=MyISAM;

    SQL- SHOW TABLES, , authors (. 2.3). .

    forums .

    . 1181

  • 54 I. 5

    I Tables_in_forum I+ +

    I authors I+ +

    1 row in set (0.05 sec)

    . 2.. authors

    ^ ^

    .

    , , -

    , ,

    : C++, PHP, Java . .

    forums : (id_forum), (name), (rule), - (logo), (pos), , 1, , 0, (hide).SQL-, forums, 2.5.

    ; 2.5. forums

    mysql> CREATE TABLE forums (mysql> id_forum INT(6) NOT NULL AUTO_INCREMENT,mysql> name TINYTEXT,mysql> rule TEXT,mysql> logo TEXT,mysql> pos INT DEFAULT NULL,mysql> hide TINYINT(l) DEFAULT NULL,mysql> PRIMARY KEY (id_forum)mysql> ) TYPE=MyISAM;

    : , - .

    , -

    . themes, - ( 2.6).

    I 2.6. themes

    mysql> CREATE TABLE themes (mysql> id_theme INT(11) NOT NULL AUTO_INCREMENT,

  • 2. MySQL 55

    mysql> name TEXT,mysql> author TINYTEXT,mysql> id_author INT(6) DEFAULT NULL,mysql> hide TINYINT(l) DEFAULT NULL,mysql> time DATETIME DEFAULT NULL,raysql> id_forum TINYINT(2) DEFAULT NULL,mysql> PRIMARY KEY (id_theme)mysql> ) TYPE=MyISAM;

    themes . (id_theme). (name). (author). (id_author). , 1, , 0 -

    (hide) ( ). (time). (idforum), -

    , .

    themes , : id_author idforum , author, - authors name. , ,

    -

    .

    posts, - ( 2.7).

    ; 2.7. posts: _____ _ ...... ;.:.... .........:..,.. ....:.... ... .'. .....i;.....^ .........:......;......:............

    mysql> CREATE TABLE posts (mysql> id_post INT(11) NOT NULL AUTO_INCREMENT,mysql> name TEXT,mysql> url TINYTEXT,mysql> file TINYTEXT,mysql> author TINYTEXT,

  • 56^ I. 5

    mysql> id_author INT (6) DEFAULT NULL,mysql> hide TINYINT(l) DEFAULT NULL,mysql> time DATETIME DEFAULT NULL,

    mysql> parent__post INT (11) DEFAULT NULL,mysql> id_theme INT(11) DEFAULT NULL,raysql> PRIMARY KEY (id_post)mysql> ) TYPE=MyISAM;

    posts . ( id jpos t ) . (name). , -

    (uri). , (file). (author). (id_author). , 1, ,

    0, (hide) -.

    (time). , (parent_

    post), 0. (idtheme), ,

    .

    , , SHOWTABLES. . 2.4.

    I Tables_in_forum I+

    +

    I authors II forums II posts II themes I+ +

    4 rows in set (0.01 sec)

    . 2.4. forum

  • 2. MySQL 57

    DESCRIBE DESCRIBE - :

    DESCRIBE table_name

    tabie_name , .

    DESCRIBE SQL MySQL.

    , , forums, - SQL- ( 2.8).

    | 2.8. DESCRIBEmysql> DESCRIBE forums;

    MySQL - (. 2.5).

    1 Field Type

    1 id forum 1 int(e)1 name 1 text1 rule 1 text1 logo 1 text1 pos 1 int(6)1 hide 1 int(1)

    6 rows in set (0.05

    ^ +

    Null 1 Key

    VESVESVESVESVES

    PRI

    1. +

    +

    Default 1 Extra 1

    NULL 1 auto increment 1NULL 1 1NULL 1 1NULL 1 1NULL I 1NULL I 1

    sec)

    . 2.5. forums

    forums, - , SHOWFULL COLUMNS FROM forums;.

    ALTER TABLE ALTER TABLE . , ,

  • 58 I. 5

    . -

    :

    ALTER TABLE table_name alter_spec

    aiter_spec (. 4.4).

    4.4. , ALTER TABLE

    ADD create_definition

    [FIRST|AFTERcolumn name]

    ADD INDEX [index_name]

    (index_col_name,...)

    ADD PRIMARY KEY

    (index_col_name,...)

    CHANGE old_col_name

    new_col_name type

    DROP col_name

    DROP PRIMARY KEY

    DROP INDEX index name

    c r e a t e _ d e f i n i t i o n .c r e a t e _ d e f i n i t i o n . F I R S T - column_name. AFTER column_name. ,

    index_name index_col_name. index_name , , -

    index_col_name

    index_col_name -

    old_col_name new_col_name t y p e

    col_name

    index name

    forums tes t name SQL-, 2.9.

    \ 2.9. .................;..;;;.;;.v;;..;.mysql> ALTER TABLE forums ADD test INT(10) AFTER name;

    DESCRIBE forums, , tes t - name (. 2.6).

  • 2. MySQL 59

    Field

    1 id_forum1 name1 test1 rule1 logo1 pos1 hide

    i- ....

    Type

    int(6)textint(IO)texttextint(6)

    h

    Null

    VESVESVESVESVESVES

    H

    Key

    PRI

    . H

    Default Extra

    NULLNULLNULLNULLNULLNULLNULL

    auto increment 1

    +

    . 2.6.

    , tes t new_test ( 2.10).

    1

    mysql> ALTER TABLE forums CHANGE test new_test text;

    . 2.7, .

    Field 1 Type

    1 id.forum1 name1 new test1 rule1 logo1 pos1 hide

    int(S)texttexttexttextint(6)int(1)

    Null

    VESVESVESVESVESVES

    Key

    PRI

    + +

    Default Extra

    NULLNULLNULLNULLNULLNULLNULL

    auto_increment 1

    7 rous in set (0.00 sec)

    . 2.7.

    , ,

    ,

    ( 2.11).

    !

    mysql> ALTER TABLE forums CHANGE new_test new_test INT (5) NOT NULL;

    . 2.8.

  • 60 I. 5

    I Field I Type I Null I Key I Default I Extra

    id_forum I int(6) I I PRI I NULLname I text I VES I I NULLnew test I int(5) I I 1 0rule I text I VES I I NULLlogo I text I VES I I NULLpos I int(6) I VES I I NULLhide I int(1) I VES I I NULL

    7 rows in set (0.00 sec)

    . 2.8.

    newtest , ( 2.12).

    1 2.12. ;

    mysql> ALTER TABLE forums DROP new_test;

    . 2.9, forums - .

    I Type I Null I Key I Default I Extra

    I id forum I mt(6j auto incrementI nameI ruleI logoI posI hide

    texttexttextint(6)

    VESVESVESVESVES

    I NULLI NULLI NULLNULLNULL

    S rows in set (0.00 sec)

    . 2.9.

    DROP TABLE DROP TABLE :

    DROP TABLE table__name [ ,table_name, . . . ]

    , forums SQL- ( 2.13).

  • 2. MySQL 61

    \ 2.13.

    mysql> DROP TABLE forums;

    DROP DATABASE DROP DATABASE , - :

    DROP DATABASE database_name

    , forum SQL-( 2.14).

    2.14. :

    mysql> DROP DATABASE forum;

    INSERT INTO... VALUES INSERT. . .VALUES -. :

    INSERT INTO table_name VALUES (values,...)

    VALUES - .

    authors , - ,

    INSERT ( 2.15)." - ..-

    ;

    2.15. INSERT \mysql> INSERT INTO authors VALUES (0, 'Maks', 423', '[email protected]',m y s q l > ' v r o w . s o f t t i m e . r u ' , ' ' , ' ' ,mysql> " , " , " , 0, 0 ) ;mysql> INSERT INTO authors VALUES (0, 'Igor1, '123', '[email protected]',mysql> 'www.softtime.ru', '', '',mysql> ", ", ", 407, 0);mysql> INSERT INTO authors VALUES (0, 'Sergey', '212', '[email protected]',mysql> 'www.sof t t ime. ru ' , ' ' , ' ' ,mysql> " , " , ' ' , 408, 0) ;

    MySQL 3.22.5, INSERT ( 2.16).

  • 62 I. 5

    mysql> INSERT INTO authors VALUES (0, 'Maks1, 423', '[email protected]',mysql> 'wvM.sof t t ime.ru ' , ' ' , '',mysql> ", ", ", 0, 0),mysql> (0, 'Igor', '123', '[email protected]',mysql> 'www.softtime.ru', '', '',mysql> ", '', ", 407, 0),mysql> (0, 'Sergey', '212', '[email protected]',mysql> 'www.softtime.ru', '', '', '',mysql> ", ", 408, 0);

    VALUES.

    , -

    INSERT:INSERT INTO tbl_name (col_namel, col_name2, ...) VALUES (valuel,value2, ...) ;

    , authors SQL-, 2.17. , - , authors, - . NULL, - AUTO_INCREMENT , 0: .

    ; 2.17. L,........................;.................................... .............;

    mysql> INSERT INTO authors (name, mail, url, about)VALUES ('Maks','[email protected]','www.softtime.ru','');

    MySQL 3.22.10 INSERT col_name=value ( 2.18).

    i 2.18. I N S E R T

    mysql> INSERT INTO authors SET name='Maks', mail='[email protected]',mysql> url='www.softtime.ru ',mysql> about='',);

    , , -

    .

  • 2. MySQL 63_

    DELETEDELETE FROM table_name [WHERE definition]

    DELETE tabiename , definition , . authors, - 2.19.

    ; 2.19.

    mysql> DELETE FROM authors;

    DELETE, UPDATE SELECT WHERE, , -

    . -

    , 1 ( 2.20).

    i 2.20.

    mysql> DELETE FROM authors WHERE id_author = 1;

    . , 2.21 , '123' 10.

    ! 2.21.

    mysql> DELETE FROM authors WHERE passw = '123' AND id_author > 10;

    AND "". "" OR.

    ( ) MySQL AND OR , - .

    AND &&, OR | |.

    SELECT SELECT :

    SELECT column,...[FROM table WHERE definition]

  • 64 I. 5

    [ORDER BY col_name [ASC | DESC], ...][LIMIT [offset], rows] column . - . ,

    *. FROM table, . WHERE, DELETE, . ORDER BY - coi_name (ASC) - (DESC). LIMIT MySQL rows offset. SELECT - forums ( 2.22).

    ; 2.22. 5 forums :

    mysql> INSERT INTO forums VALUES (0, '!.1,mysql> INSERT INTO forums VALUES (0, '2',mysql> INSERT INTO forums VALUES (0, 1,mysql> INSERT INTO forums VALUES (0, '4',mysql> INSERT INTO forums VALUES (0, '5\

    5, 0 ) ;4, 0 ) ;3, 0 ) ;2, 0 ) ;1, 0 ) ;

    forums, ( 2.23).

    ! 2.23. SELECT '

    mysql> SELECT * FROM forums;

    forums . . 2.10.

    \id_forum I name I rule | logo

    t 1 ^ f 11234

    1 5t

    I mopyul| 2| j 4| 5

    -+ + +

    pos 1+

    54321

    1

    1h +

    hide |-J-

    00000+

    . 2.10. 2.23

    , , -

    ( 2.24).

  • 2. MySQL 65

    : 2.24.

    mysql> SELECT id forum, name FROM forums;

    MySQL id_forum name (. 2.11).

    +

    1 id_forum

    I 11 21 31 I 5

    1. +name I

    1 12 1 1 15 1

    . 2.11. 2.24

    LIMIT , - SELECT. 2.25.

    j 2.25. L I M I T SELECTmysql> SELECT * FROM forums LIMIT 3;

    3 5(. 2.12).

    + + + + + + I 1d_forum I name I rule | logo | pos | hide I

    1 j *1 j2 | 2 |3 | I

    4. __.| 4. + + +

    543

    + +

    0 I I I

    . 2.12. 2.25

    LIMIT , .

    , MySQL, ( 2.26).

    ; 2.26. L I M I T

    mysql> SELECT * FROM forums LIMIT 1,3;

  • 66 I. 5

    2, 3 4 (. 2.13).

    1 -Iid_forum234

    1

    name

    2

    4h 1

    1- +-rule |

    i. +.

    logo pos432

    1

    hide000

    L

    . 2.13. 2.26

    WHERE SELECT , DELETE. , id_forum 2 ( 2.27).

    ; 2.27. SELECT

    mysql> SELECT * FROM forums WHERE id_forum > 2;

    . 2.14.

    I 1d_forum | name I rule I logo | pos | hide |+ + + + 1. + +3 |

    4 I 45 I 5

    +

    321

    000

    . 2.14. 2.27

    -

    ORDER BY ( 2.28).

    \ 2.28.

    mysql> SELECT * FROM forums WHERE id_forum > 2 ORDER BY pos;

    id_forum - , pos. . 2.15.

    J. + 1id_forum | name

    5 | 4 | 43 |

    + +

    rule | logo | pos

    ! ! :

    1 1

    hide |

    1111

    . 2.15. 2.28

  • 2. MySQL 67_

    SELECT - forums. SQL-, 2.29, hide = 1 ( 2.29). hide .

    : 2.29. forums

    mysql> INSERT INTO forums VALUES (0, '', " , " , 5, 1 ) ,mysql> (0, '7', " , " , 4, 1 ) ,mysql> (0, '8\ " , " , 3, 1 ) ,mysql> (0, '', " , " , 2, 1 ) ,mysql> (0, '', ' ' , " , 1, 1) ;

    , -

    GROUP BY, 2.30.

    2-30. GROUP BY/:....

    mysql> SELECT * FROM forums GROUP BY hide;

    SQL-, 2.30, . 2.16.

    I id_forum | name | rule I logo | pos | hide I~~1~1 t ~ t " I 5 t 0 ]

    13 | j 5 I 1 I

    . 2.16. SQL- 2.30

    UPDATEUPDATE table

    SET col_namel=exprl [, col_name2=expr2 ...][WHERE definition][LIMIT rows]

    UPDATE table - . SET -,

    . WHERE, -

  • 68 I. 5

    , , . -

    . LIMIT .

    2.31 2 (), hide 1, .

    ; 2.31. UPDATE i

    UPDATE forums SET name='PHP\ h i d e = l WHERE id_forum=2;

    SHOW SHOW - , MySQL. SHOW CHARACTER SET , MySQL (. 2.17).

    Charset

    Mg51 at i nlU11S

    1 si isI t1s620I euckrI gb23121 gbkutf8ucs2binary

    +.

    Description Default collation

    -i

    big5 chinese_cilatinl swedish_ciuqis_qapanese_cisnis_japanese_citis62O thai cieuckr korean cigb2312_chinese_cigbk_chinese_ciutf8_general ciucs2 general cibinary

    ^

    hMaxlen

    2 |1 132 11 |2 |2 12 |3 |2 |1 |

    +

    . 2.17. SHOW CHARACTER SET.

    SHOW COLUMN TYPES , MySQL.

    SHOW CHARACTER SET SHOW COLUMN TYPES , MySQL 4.1.

    ,

    ( 2.32).

    i 2.32. SHOW

    mysql> SHOW FIELDS FROM authors;

  • 2. MySQL 69

    . 2.18.

    1 Field

    1 id_author1 name1 passu1 email1 url1 icq1 about1 photo1 time1 last time1 themes1 statususer

    h ,

    Type

    int(6)texttexttexttexttexttexttextdatetimedatetimeint(1Q)int(2)

    i-

    Null

    VESVESVESVESVESVESVESVESVESVESVES

    Key I Default Extra

    PRI NULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULL

    auto increment

    . 2.18. 2.32

    , . 2.18, - DESCRIBE authors SHOW COLUMNS FROM authors.

    SHOW FULL COLUMNS FROM authors .

    -

    ( 2.33).

    i 2.33. :

    mysql> SHOW INDEX FROM authors;

    SHOW PROCESSLIST , (. 2.19). SHOW STATUS .

    SHOW TABLE STATUS, : , , ,

    , , , -

    , AUTOINCREMENT . .

  • 70

    11

    -+

    11

    -+

    Id

    1

    1

    1

    User

    ODBC

    1 Host

    1 127.0.0.1

    1

    .3008 1

    1. PHP 5

    db 1 Command 1 Time 1 State 1 Info

    forum 1 Query I 0 1 NULL 1 SHOW PROCESSLIST

    . 2.19.

    , SHOW DATABASES SHOWTABLES , , .

    ( ^ mysqlshow, MySQL, , SHOW. , - ,

    mysqlshow . ( , mysqlshow f orum), .

    (LIKE w NOT LIKE) MySQL , - , . . .

    LIKE NOT LIKE, -. "_"

    , "." ,

    "%" - "*" .

    , S Q L - S E L E C T n a m e , u r l FROM a u t h o r s WHERE n a m e L I K E ' S % ' ; authors, 2.15, - , "s"

    (. 2.20).

    I Sergey I www.softtime.ru |

    . 2.20.

  • 2. MySQL 71_

    COUNT COUNT , ., SQL-, 2.34, - .

    - ;

    '.34. authors ;

    mysql> SELECT COUNT(*) FROM authors;

    : -, , 2.35, - 2.34.

    1 2.35.

    mysql> SELECT COUNT(name) FROM authors;

    . -

    DISTINCT, - . , 2.36 URL . , URL , - URL .

    2.36. DISTINCT 1

    mysql> SELECT DISTINCT url FROM authors;

    DISTINCT COUNT. - , . -

    SQL-, 2.37.

    mysql> SELECT COUNT(DISTINCT name) FROM authors;

    , -

    2.34, . COUNT GROUP BY. , SQL-, 2.38.

  • 72 I. 5

    \ 2.38. COUNT GROUP BY \. . . . i . . . . , , . . . , : . . . . . . . . ; . . , , . . . . . * . . . , , . . . , , . . . . . . . . . . . . . . . . . .

    mysql> SELECT hide, COUNT(*) FROM forums GROUP BY hide;

    . 2.21: 5 5 .

    I hide | COUNT(') II ] " i t1 1 1 5 |^ + +

    . 2.21. SQL- 2.38

    , MySQL, , .

    , , -

    :

    FROM , SQL-: FROM table l , talble2;

    -

    : tablel .value, table2.value.

    ( ^ , -

    , .

    , ,

    SQL-, 2.39.

    ; 2.39. '

    mysql> SELECT count(*)mysql> FROM themes, forums

    mysql> WHERE themes.id_forum = forums.id_forummysql> GROUP BY forums.id_forum;

  • 2. MySQL 73_

    -

    , .

    2.40.

    2.40.

    mysql> SELECT count(*)mysql> FROM authors, postsmysql> WHERE authors.name = posts.authorsmysql> GROUP BY authors.name;

    , posts posts.authors, , authors, SQL- . , 2.40, (authors.themes) - .

    .

    posts , - authors, - ,

    (authors, name), (authors . id_name).

    ( ) , -

    , ,

    , .

    ,

    Web-. - INT, authors, posts (posts.name) e-mail (posts, email).

    SQL, , .

    ( ), , MySQL .

  • 74 I. 5

    ( ) ISAM, MylSAM HEAP . BDB InnoDB.

    ,

    . -

    ,

    , , -

    .

    , ,

    ACID (Atomic Consistent Isolated Durable), :

    .

    ,

    ;

    .

    ;

    . ;

    . -

    .

    , -

    -, . ,

    100 . .

    , -

    : , - . , ,

    SELECT, . -

    . SELECT , 100. .

    100. , -

    , , 100 99. -

    UPDATE, , -, ,

    99 98.

  • 2. MySQL 75_

    SELECT UPDATE .

    , ,

    , -

    .

    -,

    sum, - :

    UPDATE account SET balance = balance - sum WHERE name = 'client';UPDATE account SET balance = balance + sum WHERE name = 'bookshop';

    , .

    ( ) . -

    , -

    LOCK TABLES UNLOCK TABLES. , --

    , UPDATE s t o r e SET count = count - 1 ; .

    MySQL auto-commit (-), . . . -

    , , -

    BEGIN. COMMIT. - , ROLLBACK.

    ( ) COMMIT ROLLBACK - , B E G I N .

    ( )

    SET AUTOCOMMIT = 1 SET AUTOCOMMIT =0;.

    forums, - 2.5, innoDB( 2.41).

  • 76 I. 5

    ; 2.41. forums I

    mysql> CREATE TABLE forums (mysql> id_forum INT(6) NOT NULL AUTO_INCREMENT,mysql> TINYTEXT,

    mysql> rule TEXT,

    mysql> logo TEXT,

    mysql> pos INT DEFAULT NULL,

    mysql> hide TINYINT(l) DEFAULT NULL,mysql> PRIMARY KEY (id_forum)mysql> ) TYPE=InnoDB;

    BEGIN, COMMIT. ( 2.42).

    mysql> BEGIN;

    mysql> INSERT INTO forums SET name = ' I', hide = 0, pos = 1;mysql> INSERT INTO forums SET name = ' II', hide = 0, pos = 2;mysql> COMMIT;

    mysql> SELECT id_forum, name FROM forums;

    SQL- 2.42 . 2.22.

    + 1-I id_forum | namet +

    1 | I2 | II

    . 2.22. SQL- 2.42

    mysqi, COMMIT .

    , -

    ROLLBACK ( 2.43).

  • 2. MySQL 77

    \

    mysql> BEGIN;

    mysql> INSERT INTO forums SET name - ' III', hide = 0, pos = 1;mysql> INSERT INTO forums SET id_forum - 1, name = " IV, hide = 0;ERROR 1062 (23000): Duplicate entry 1 for key 1mysql> ROLLBACK;

    mysql> SELECT id_forum, name FROM forums;

    . 2.23, - forums ROLLBACK, - .

    I id_forum | name |* + +

    1 | I2 I II

    . 2.23. SQL- 2.43

    2.2.7.

    SQL-. - ,

    .

    .

    ( ^ SQL-,

    . .

    SELECT, - INSERT, DELETE UPDATE. -, , .

  • 78 I. 5

    ,

    , ,

    .

    . -

    : f i r s t , second third, value 1000 , - 1 1000. , 2.44, 1000 , .

    ; 2.44.

    mysql> SELECT first.value, second.value, third.valuemysql> FROM first, second, thirdmysql> WHERE first.value = second.value AND first.value = third.value;

    , -

    2.44 , (1000x1000x1000), - 1000 . MySQL : (INDEX). -

    ;

    (UNIQUE, PRIMARY KEY). ;

    (FULLTEXT).

    ( ^ FULLTEXT TEXT MylSAM. FULLTEXT - 9, .

    -

    CREATE TABLE - CREATE INDEX ALTER TABLE, - 2.45.

  • 2. MySQL 79

    ! 2.45. l|fll>i|ia.ttti'>rik'>rll4'II.it>lir>I.I.IIIIlII.>Iti|fl|l.M.fl'>li*|l|l||||tl>l>llII.|||lltlll|llli

    mysql> ALTER TABLE table ADD INDEX index_name (column);

    2.45 table index_name column. .

    (~ ) CREATE INDEX INDEX UNIQUE.

    UNIQUE PRIMARY KEY , , PRIMARY KEY PRIMARY KEY, , .

    ( ) DROP INDEX ALTER TABLE.

    ,

    . , , -

    SELECT, - SQL-. , , WHERE. 2.46.

    mysql> SELECT column // column mysql> FROM tablemysql> WHERE index = exper; // index

    SQL-, 2.46, column , - index .

    , 1020 . , - -

    . -

    , .

  • 8 I. PHP S

    2.2.8. MySQL SQL -, .

    . -

    ,

    .

    BENCHMARK (num, expr), num expr. . 2.24.

    mysq1> SELECT BENCHMARK(loooooo,1+1);+ +I BENCHMARK(IOOOOOO,I+I) I

    1 row in set (O.O3 sec)

    . 2.24. BENCHMARK

    BENCHMARK MySQL EXPLAIN, , -

    , , -

    , .

    E X P L A I N , - DESCRIBE .

    MySQL. .

    -

    . , CHAR(IO) CHAR(IO) VARCHAR(IO), CHAR (12) VARCHAR(12). INT BIGINT ..

    , , -

    myisamchk analyze. - ,

    .

    LIMIT, .

  • 2. MySQL 81

    VARCHAR, TEXT BLOB, .

    , ,

    OPTIMIZE TABLE.

    -

    . MySQL , -, . , , column , 2.47 .

    ! 2.47. ; ;

    mysql> SELECT * FROM table WHERE column = 4;mysql> SELECT * FROM table WHERE column = '4';

    ; , column , .

    2.3. MySQL API MySQL PHP-, , MySQL.

    2.3.1. PHP MySQL -

    , MySQL . , - ,

    .

    ( ^SQL : SQL (ApplicationProgram Interface, API). - SQL . MySQL, . - , -

    .

    MySQL.

  • 82 I. 5

    mysql_connect :

    resource mysql_connect ([string server [,string username [,string password [,bool new_link [,int client_flags]]]]])

    ,

    server. username password.

    mysqi_connect - ,

    . -

    new_iink TRUE, . c l i e n t f l a g s :

    MYSQL_CLIENT_COMPRESS - ;

    MYSQL_CLIENT_IGNORE_SPACE SQL- - ;

    MYSQL_CLIENT_INTERACTIVE interactive__timeout - , -

    .

    .

    :server = ' l o c a l h o s t : 3 3 0 6 ' , username password .

    ,

    FALSE ( 2.48).; ; . ' " . . . . . . . . . . .

    : 2.48. mysql_connect

  • 2. MySQL 83

    $dbcnx = @mysql_connect($dblocation,$dbuser,$dbpasswd);if (!$dbcnx) // 0, {echo("B ,

    .");exit ();

    ( ) , -

    , 2.48 mysql_connect @.

    $dbiocation, $dbuser $dbpasswd , , , (, config.php), -, - MySQL.

    mysql_close MySQL. :

    bool mysql_close ([resource link_identifier])

    -

    i ink_identif ier, , - . TRUE FALSE .

    2.49 .

    I 2.49. mysql;....... ..................

  • 84 I. 5

    }if(mysql_close($dbcnx)) // (echo(" ");

    }else{echo("He ");

    mysql_select_dbbool mysql_select_db (string database_name [, resource link_identifier]) USE SQL-, . . mysqi_select_db - , SQL- . -

    database_name resource. - TRUE FALSE - . 2.50.

    | 2.50. mysql s e l e c t db I! :..;......: .....,.........;. ~....:...:.......~ .:...;.:.....;...;.,..;

  • 2. MySQL 85

    $dbname = "softtime";$dbuser = "root";$dbpasswd = "";$dbcnx = @mysql_connect($dblocation,$dbuser,$dbpasswd);if (!$dbcnx){echo( "B ,

    ." );exit () ;

    }if (!@mysql_select_db($dbname, $dbcnx)){echo( "B ,

    ." );e x i t ( ) ;

    mysql_query SQL- - :

    resource mysql_query (string query [, resource link_identifier])

    query, (iink_identif ier) , - mysql_connect.

    ( ~ ^ , ,

    mysql_connect, .

    ( ) mysql_query () -, mysql, .

    FALSE . 2.52 , authors forum, , .

    4 3. 1181

  • 86 I. 5

    2. ;... ..... *........: .....

  • 2. MySQL 87

    mysq l

  • 88 I. 5

    IIO3HLU4H

    CKpbiTbM/flocTynHbm

    // , while(list($id_forum, $name, $rule, $logo, $pos, $hide) =

    mysql_fetch_row($ath)){echo "

    $id_forum$name$rule$logo$pos$hide

    echo "";}else(

    echo "Error: " .mysql_error () . ""exit(');

    mysql_fetch_assoc mysqi_f etch_assoc () . :

    array mysql_fetch_assoc (resource result) result , mysqiquery . , - , FALSE, . mysqi_fetch_assoc 2.55.

    : 2.55. mysql fetch_assoc \; ; ;'...: ....'...:.:.: ; ;

  • 2. MySQL 89_

    $ath = mysql_query("select * from forums;");if ($ath){// echo "";echo "

    Ha3BaHnepaanpMBeTCTBMe

    CKpbiTbiii/flocTynHbM

    // , , // // : // : extract($ath); , // $id_forum, $name, $rule, $logo, $pos,// $hide.while($author = mysql_fetch_assoc($ath)){echo "

    ".$author['id_forum']".$author['name']."".$author['rule']."".$author['logo']."".$author['pos']."".$author['hide']."

    echo "";

    else

    echo "Error: ".mysql_error()."";exit () ;

  • 90_ I. 5

    mysql_fetch_array ,

    mysqi_query(), . ( -) . :array mysql_fetch_array (resource result [, int result_type]) result -, mysqi_query. - :

    MYSQL_ASSOC ; MYSQL_NUM ; MYSQL_BOTH ,

    , .

    ( ) MYSQL_BOTH.

    ( } mysql_fetch_array MYSQL_ASSOC MYSQL_NUM, mysql_f etch_assoc mysql_f etch_row .

    , .

    authors ( 2.56).

  • 2. MySQL 91

    ".$author['name']."".$author['passw']."".$author['email']."".$author['url']."

    echo "";

    else

    echo "Error: ".mysql_error () . "";exit () ;

    mysql_fetch_object mysqi_query () ,

    . :

    object mysql_fetch_object (resource result) result , mysqi_query(). , FALSE, .

    , , .

    2.57 , authors , URL e-mail authors.

    include "config.php";$ath = mysql_query("select * from authors;");if($ath)

    while($row = mysql_fetch_object($ath))

  • 92 I. 5

    {echo "name: ".$row->name."";echo "url: ".$row->url."";echo "email: ".$row->email."";

    else

    {echo "Error: ".mysql_error () . ""exit ();

    mysql_num_fields -

    :

    int mysql_num_fields (resource result)

    result , mysqi_query.

    mysql_num_rows , ,

    mysqi_query(), :int mysql_num_rows (resource result)

    result , mysqi query ().

    SELECT. , INSERT, UPDATE, DELETE, - mysql_af f ected_rows () .

    2.3.2. MySQL

    MySQL, ,

    .

  • 2. MySQL 93

    MySQL , MySQL, - ,

    MySQL Apache, . -

    PHP-. - . -

    0 10. -,

    , -

    :

    devices , ; tes t s , .

    CREATE, , 2.58. devices : id_device name . tes t s : id_test - , mark , - , putdate i d d e v i c e - devices . id_device id_test devices t e s t s .

    : -

    i 2.58. devices tests

    CREATE TABLE devices (id_device INT(11) NOT NULL,name VARCHAR(20) NOT NULL,UNIQUE KEY id_device (id_device)

    ) TYPE=MyISAM;CREATE TABLE tests (

    id_test INT(11) NOT NULL,mark TINYINT(4) NOT NULL,putdate DATETIME NOT NULL,id_device INT(11) NOT NULL,UNIQUE KEY id_test (id_test)

    ) TYPE=MyISAM;

    , . -

  • 94 I. 5

    . 2.25 - ( t e s t s ).

    idjest

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    mark

    7

    7

    6

    9

    3

    7

    7

    8

    8

    8

    9

    id_device

    3

    4

    1

    2

    4

    3

    1

    2

    3

    1

    2

    \

    \

    4

    U

    i

    tests

    id device name

    Maxtor 6Y080MO

    Maxtor 6Y120PO

    SumsungSP1604N

    Sumsung SP6003H

    devices

    . 2.25. : t e s t s devices

    ,

    devices . :

    devices, t e s t s , devices;

    devices, te s t s .

    2.59 .

  • 2. MySQL 95

    2.59.

  • I. 5

    else

    echo "Error: " .mysql_error () . "";exit ();

    // id_device, // $value tests.// tests // id_test$query = "SELECT MAX(id_test) AS id_test FROM tests";$tst = mysql_query($query);if($tst){// id_test// tests $test = mysql_fetch_array($tst) ;$id_test = $test['id_test'] + 1;// tests mysql_query("INSERT INTO tests

    VALUES ($id_test, '$value\ NOW(), $id_device)");}else

    {echo "Error: ".mysql_error()."";exit();

    else

    echo "Error: " .mysql_error () . "";exitO;

    2.59 SQL- "SELECT MAX(id_test) AS id_test FROMtests" . MAX MySQL,

  • 2. MySQL 97

    , AS MAX(id_test) i d t e s t . 2.59 - .

    ; , SELECT i d t e s t . , -

    id_device id_test devices tes t s AUTOINCREMENT. , - ALTER ( 2.60).

    : 2.60. devices tests

    ALTER TABLE t e s t sCHANGE i d _ t e s t i d _ t e s t INT(11) NOT NULL AUTO_INCREMENT;ALTER TABLE d e v i c e sCHANGE id__device id_dev ice INT (11) NOT NULL AUTO_INCREMENT;

    INSERT i d d e v i c e i d t e s t 0 NULL MySQL , - .

    (~ ) AUTOINCREMENT -, , 0 NULL.

    ,

    . -

    PHP- 2.59 , " 10", -

    10. , $id_device, , - , SQL- . $id_device MySQL, -? MySQL, - LAST_INSERT_ID{) , AUTO_INCREMENT, .

  • 98 I. 5

    ( ^

    AUTO_INCREMENT, LAST_INSERT_ID () 0.

    mysqi_insert_id (), AUTO INCREMENT .

    ( ^ ,

    AUTO_INCREMENT. , - LAST_INSERT_ID () m y s q l _ i n s e r t _ i d ( ) .

    2.59 2.61.

    2.59

  • 2. MySQL 99

    $id_device = mysql_insert_id();}// id_device, // $value tests.// tests mysql_query("INSERT INTO tests

    VALUES (NULL, '$value\ NOW(), $id_device)");}else{

    echo "Error: " .mysql_error () . "";exitO;

    2.61, , SQL- . -

    devices, . 2.62 , - .

  • 100 I. 5

    FROM tests

    WHERE id_device=".$device['id_device'];$tst = mysql_query($query_test);if($tst)f$mark = 0;// while($mark += mysql result($tst));

    a

    echo "".$device[ 'name' ] . "$mark";}else{echo "Error: ".mysql_error()."";exit ();

    // echo "";

    }else{echo "Error: ".mysql_error () . "";exit ();

    2.62 . -

    , ,

    MySQL . AVG(expr) ,

    ,

    ( 2.63).

    2.63. ;

  • 2. MySQL 1_

    $query_device = "SELECT devices.name AS name, AVG(tests.mark) AS markFROM devices, testsWHERE devices.id_device = tests.id_deviceGROUP BY devices.di_device";

    $dev = mysql_query($query_device);if($dev){// echo "";while($device = mysql_fetch_array($dev)){

    echo "".$device['name']."-

    ".$device['mark']."

    // echo "";

    else

    echo "Error: " .mysql_error () . "";exit();

    2.63, , ,

    - SELECT, .

    NULL, SELECT NULL, - i s se t ().

    ( ) , NULL, .

    NULL tes t , - ( f i rs t , second third), 2.64.

  • 102 I. 5

    2.64. H U L L ...;........

  • 2. MySQL 103_

    $query = "SELECT first, second, third FROM test";$tst = mysql_query($query);// if($tst){echo "Error: ".mysql_error()."";exit();

    }// echo "";while(list($first, $second, $third) = mysql_fetch_row($tst)){

    echo "";if($first NULL) echo "-";else echo "$first";if($second === NULL) echo "-";else echo "$second";if($third === NULL) echo "-";else echo "$third";echo "";

    }// echo "";

    .

    , 2.65 , - , .

    .

    mysqi_num_rows (), - ( 2.66).

  • 104 I. 5

    {echo "Error: " .mysql_error () . "";exit();

    }// , if(mysql_num_rows($tst)>0){// echo "";while (list ($first, $second, $third) = mysql_fetch__row ($tst) ){echo "";if($first NULL) echo "-";else echo "$first";if($second === NULL) echo "-";else echo "$second";if($third === NULL) echo "-";else echo "$third";echo "";

    }// echo "";

    members, (name), - (email) (uri) . name , email ur i -, email uri - NULL. CREATE, , - 2.67.

    2.67. members

    CREATE TABLE members (name VARCHAR(20) NOT NULL DEFAULT ",email TINYTEXT,uri TINYTEXT

    ) TYPE=MyISAM;

  • 2. MySQL 105_

    , ,

    : , e-mail, , . ,

    , 2.68.

    | 2.68.

  • 106 I, 5

    II

    echo "";while(list($name, $url) = mysql_fetch_row($url))

    if ($email !== NULL) echo "$name$url";// echo "";

    2.68 , - . , : SELECT SQL- ur i , SQL-. - $mem , - . -

    mysqi_data_seek(), :bool mysql_data_seek (resource result_identifier, int row_number)

    ,

    resui t_ident i f ier , mysqi_query , . TRUE FALSE .

    2.68 ( 2.69).

    mysql_data_seek

  • 2. MySQL 107_

    {// I // echo "";while(list($name, $email, $url) = mysql_fetch_row($mem))if($email !== NOLL) echo "$name$email";

    // echo "";// mysql_data_seek($mem,0);// II // echo "";while(list($name, $email, $url) = mysql_fetch_row($mem))if ($email !== NULL) echo "$name$url";

    // echo "";

    , SQL-.

    -

    2.58 t e s t s devices. - devices , , tes t s . , -

    devices. , - 2.70, $id_device.

    !

  • 108 I. 5

    {

    mysql_query("DELETE FROM devices WHERE id_device = $id_device " ) ;

    2.4. phpMyAdmin -

    MySQL, ? - SQL , - ,

    , MySQL. Web- MySQL phpMyAdmin. , , - MySQL, - , .

    MySQL SQL, 47 , . phpMyAdmin - -.

    phpMyAdmin , - SQL- MySQL: ;

    CD , , , ; ;

    , ;

    SQL-, ; ;

    ;

    ;

    CVS, XML Latex; ;

    ;

    MylSAM; PDF- ;

  • 2. MySQL 1_09_

    ;

    innoDB .

    ( ^ phpMyAdmin - Web- http://www.phpmyadmin.net/home_page/downloads.php.

    phpMyAdmin 2.5.5-pll. , , : 4.1.0 ( JPEG--

    GD2); MySQL 3.23.32; Web-.

    2.4.1. phpMyAdmin phpMyAdmin .1.

    Web- ( phpMyAdmin). DocumentRoot, 1. - ( - ), - , 3, Web-, , FTP.

    2. config.inc.php , - ,

    . "" , MySQL. , locaihost. - $cfg['PmaAbsoiuteUri'] - phpMyAdmin: Web- -

    phpMyAdmin, http://localhost/phpMyAdmin. , phpMyAdmin.

    3. , phpMyAdmin,, HTTP-AUTH, phpMyAdmin -

    HTTP cookie-.4. phpMyAdmin.

    (locaihost) -

  • 110 I. 5

    phpMyAdmin Web-, - URL: http://locaIhost/phpMyAdmin/index.php. ,

    . 2.26.

    I 1'(11 liK-ulhust piipMyAilnrin 2*!5 pll Mkmsoll Internet L xpkm1 ( " \^J} [*] ^z)

    ; I) i , " ;;> ^ ; ftthttp://bcalhost/tools/phpMyAdmin/ j>] |

    phpMyAdmin 2.5.5-MySQL 4.0.17-nt localhost root@localhost

    phpmyadmln] pma__bookmark1 pina_coiumn_lnfo pma_mstorya pmajxlf_pages pma_relatton) pma_taba pma_tabte_in(o

    MySQL

    []

    |

    MySQL

    MySQL[]

    []I- MySQL

    []

    I-

    phpMyAdmin- Language (*): |Russian (ru-win125i)

    i phpMyAdmin

    phpMyAdmin[ChangeLog] [CVS] [Lists]

    i-2i httpi//toosihpst/toois/phpMyAdniin;'images/vertical jne.png.. f * J

    . 2.26. phpMyAdmin

    5. phpMyAdmin (, -, SQL-, PDF-, - . .), phpmy-admin . SQL-, scripts/create_tables.sql. phpMy-Admin . - .

    , . 2.27, create_tables.sql .

  • 2. MySQL 111

    phpMyAdmin - Microsoft Internet Explorer

    SQL

    SQL () (forum[]DROP DATABASE IF EXISTS phpmyadmin"; _ dCREATE DATABASE IF NOT EXISTS ' phpmyadmin'; _ J

    (backquotes are not supported in USE)USE phpmyadmin,GRANT SELECT, INSERT, DELETE, UPDATE ON'phpmyadmin'.*TO

    'pma'@localhost; _J ^^'"]

    I I & SQL--

    :

    bj

    . 2.27.

    phpMyAdmin -, $cf g [' PmaAbsoluteUri' ] .

    phpMyAdmin.

    SQL- create_tables.sql config.inc.php. -, -

    2.72.; - ' . . . . . . . . . . . . .

    v . . .

    ; 2.72. cohfig.inc.php

    // , // phpMyAdmin. phprayadmin.$cfg["Servers'][$i]['pmadb'] = 'phpmyadmin';// , // phpmyadmin.$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';$cfg['Servers'][$i]['relation'] = 'pma_relation';

  • 112 I. 5

    $cfg['Servers'][$i] ['table_info'] = 'pma_table_inf';$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';$cfg['Servers'][$i]['column_inf'] = 'pma_column_inf';$cfgt'Servers'][$i]['history'] = 'pma_history';

    phpMyAdmin - MySQL, : . -

    , -

    .

    ( ^ config.inc.php php-, PHP-. $ i . phpMyAdmin : $ c f g [ ' S e r v e r s ' ] [ 0 ] , $ c f g [ ' S e r v e r s ' ] [1] . .

    phpMyAdmin , - , ,

    , .

    ,

    -

    , .

    phpMyAdmin -:

    -

    config.inc.php; cookie; http-. config.inc.php - 2.73.

    | 2.73 :$cfg['Servers'][$i]['auth_type'] = 'config';$cfg['Servers'][$i]['user'] - 'user';$cfg.['Servers'][$i]['password'] = 'password';

  • 2. MySQL 113

    $cfg[ 'Servers ' ] [$i][ 'auth_type ' ] , , -

    .

    $ c f g [ ' S e r v e r s ' ] [ $ i ] [ ' u s e r ' ] ,

    $cfg ['Servers'] [$i] ['password'].

    , -

    MySQL, $i++. , - , -

    .

    MySQL, $cfg[ 'Servers ' ] [$ i ] [ 'hos t ' ] - . -

    , . 2.28.

    ' phpMyAdmin localhost - phpMyAdnvn 2.5.5-pIl - Microsoft Internet Explorer

    ^J * - ] , , 1,,'- \ http.7/bcalhosc/tools/phpMyAdmin/

    [( )

    phpMyAdmin 2.5.5-

    MySQL 4.0.17-nt localhost igor@localhost

    | localhost (igor)localhost (igor)

    |mysq[1.nodex,m (sofflime)MySQL

    phpMy/

    . 2.28.

    -

    MySQL.

  • 114 I. 5

    phpMyAdmin - G R A N T phpMyAdmin.

    cookie.

    $cfg [' Servers ' ] [$i] [ ' auth_type ' ] Ha "cookie". - .

    phpMyAdmin 2.5.2, cookie-- blowfish- .

    cookie, $cfg[ 't>iowfish_secret' ] - , .

    phpMyAdmin : " (blowfish_secret)".

    1'H phpMyAdmin 2.5.5-pll - Microsoft Internet Explorer

    ^ J ) ^ _ J i*) jj jy !() | . ' S',V ^ } * *

    | : : http://bcalhost/tools/phpMvAdmlnflndex.php?lang=ru-winl25l&server=l_j fl

    phpMyAdmin 2.5.5- -

    Language: (Russian (ru-win1251) | |

    (Cookies .)

    : |igor:

    1 i 1

    1!

    |_||1i j

    I j

    . 2.29. phpMyAdmin cookie

  • 2. MySQL 115

    , phpMyAdmin (. 2.29). -

    HTTP-. - phpMyAdmin $cfg[ 'Servers'] [$i] ['auth_type' ] "http".

    -

    Apache.

    Apache, , 1, - (. 2.30).

    | localhostsi w

    phpMyAdmin tocalfrost

    : [ f i igor

    : ||

    I CojspaHHTb

    |_?J_xj|

    1

    . 2.30. h t t p

    phpMyAdmin , - ,

    Web- .

    2.4.2. phpMyAdmin phpMyAdmin - config.inc.php, -

  • 116 I. 5

    . -

    , phpMyAdmin.$cfg['PmaAbsoluteUri'] string (URL) phpMyAdmin. -, http://www.your_web.net/path_to_your_phpMyAdmin_directory/ http://localhost/phpMyAdmin/.

    ^

    URL , , URL.

    2.3.0, , phpMyAdmin - .

    $cfg['PmaAbsoluteUri_DisableWarning'] boolean $cfg[ 'PmaAbsoluteUri' ] -

    phpMyAdmin, , - $cfg[ 'PmaAbsoluteUri1 ]. - ,

    , TRUE - .

    $cfg['blowfish_secret'] string 2.5.2, cookie- - blowfish- . - cookie-, 1- , blowfish-, .

    $cfg['Servers'] array 1.4.2, phpMyAdmin - MySQL. $cfg[ 'Servers' ] - . , -

    $cfg[ 'Servers ' ] [$ i ] [ 'host 1 ] , $cfg[ 'Servers ' ] [$ i ] [ 'host ' ] MySQL . . , , -

    .

    $cfg['Servers'][$i]['host'] string IP- $i-ro MySQL-. , "locaihost1'.

  • 2. MySQL 1J7_

    $cfg['Servers'][$i]['port'] string $i-ro MySQL-. , , 3306. - localhost, MySQL , , .

    , -

    , "127.0.0.1".$cfg[ 'Servers ' ][$i][ ' socket ' ] string

    . .

    $cfg['Servers'][$i][ 'connect_type'] string

    , MySQL-. : soket tcp. - tcp, TCP/IP - ,

    .

    ( ) soket , MySQL - , Web-.

    $cfg['Servers'][$i]['controluser'] string$cfg['Servers'][$i]['controlpass'] string

    , , ,

    .

    $cfg[ 'Servers '][$i][ 'auth_type'] string [ 'h t tp ' | ' cookie ' I ' conf ig 1 ], :

    'config' : config.inc.php;

    'cookie' , 2.3.3. cookie.

    ;

    'http' , MySQL HTTP-.

    $cfg['Servers'][$i]['user'] string$cfg['Servers'][$i]['password'] string

    /, phpMyAdmin - MySQL-. HTTP - cookie .

    5 3. 1181

  • 118 I. 5

    $cfg[ 'Servers '][$i][ 'only_db'] str ing or array , , -

    .

    , . , ,

    $cfg[ ' servers ' ] [$i] [ 'only_db' ] = ' t e s t ' ; , , , -

    , MySQL (mysql) phpMyAdmin (phpmyadmin), (. 2.31).

    I 3 phpMyAdmin localhost - phpMyAdmin 2.5.5-pll - Microsoft Internet Explorer

    j - : ) - [xj ;|] 1 '-;'-;' ^ J 1 -J; j-igihttp://tocalhost/tools/phpMyAdmin/index.php?(ang=ai-winl251&server=l [ ^ J i

    test (-)

    phpMyAdmin 2.5.5-MySQL 4.0.17-nt localhost igor@localhost

    MySQL

    : []

    MySQL

    MySQL[]

    . ..

    phpMyAdmin- Language (*): | Russian (ru-win1251)

    phpMyAdmin

    I- phpMyAdmin[ChangeLog] [CVS] [Lists]

    . 2 . 3 1 . t e s t ,

    , -

    :

    $ c f g [ ' S e r v e r s ' ] [ $ i ] [ ' o n l y _ d b ' ] = a r r a y ( ' t e s t ' , ' d b l ' , ' d b 2 ' ) ; .

    MySQL, -, .

  • 2. MySQL 1J9_

    -

    . , $ c f g [ ' S e r v e r s ' ] [ $ i ] [ ' o n l y _ d b ' ] = a r r a y ( ' d b 3 ' ,db4', ' * ) ; , db3 db4, .$cfg['Servers'][$i]['verbose'] string -

    . -

    .

    $cfg['Servers'][$i]['pmadb'] string 2.3.0, phpMyAdmin . ,

    , . -

    , .

    phpMyAdmin, - . Web- ,

    ,

    .

    $cfg['Servers'][$i]['bookmarktable'] str ing 2.2.0, phpMyAdmin - SQL-. - SQL-, scripts/create_tables.sql, ( bookmarktable) .

    $cfg['Servers'][$i]['relation'] string 2.2.4, . ( ). phpMyAdmin : ;

    " " ,

    ;

    /; , -

    ;

    PDF- . SQL-, scripts/create_tables.sql. ( relation) :$cfg['Servers'][$i]['table_info'] string

  • 120