Открыть Электронные книги
Категории
Открыть Аудиокниги
Категории
Открыть Журналы
Категории
Открыть Документы
Категории
, MySQL
JavaScript
CSS
[^
- - - -
-- - -
- -
2013
.................................. ............................... 21
.............................................................25
1. -... 26
2. ,
.................................. ...........................39
3. ...................................................62
4.
............... ............................................90
5. ...................................... 118
6. ................................................. 145
7. ............... 160
8. MySQL............................ .................188
9. MySQL...............................................230
10. MySQL ..................254
11. ............................................. 281
12. Cookie, ........................ 298
13. JavaScript.......................................... 318
14.
JavaScript.................................................... 338
15. , JavaScript................. 356
................................................................................... 21
...................................................... 21
, ...................................... 21
..........................................................................22
............................................................. 22
, ...................................... 23
........................................................... 24
.................................................................................24
............................................................................. 25
1. - ... 26
HTTP HTML: , -.................................27
.................................................. 27
, MySQL, JavaScript CSS.................... 29
...............................................................31
M ySQL......................................................... 32
JavaScript......................................................33
CSS...............................................................34
- Apache........................................................................... 35
.................... 36
, ......................................................... 36
.................................................................... 38
2. ,
.................................................................................39
WAMP, MAMP LA M P ......................................................... 40
WAMP Windows.................. '..............................40
......................................................... 47
W AM P........................................................... 49
Mac OS X .................................................50
MySQL...................................................................53
MySQL ...................... 54
............................................................... 54
LAMP Linux...................................................................56
............................................................. 57
...................................................................... 57
FTP.................................................................57
.................................................... 59
ID E ..........................................................................60
.................................................................... 61
3. .................................................................62
HTM L.................................................................... 62
.................................................................63
, .................................................... 64
.................................................................................65
.................................................. 65
...............................................................66
........................................................67
........................................................................... 71
....................................... 74
......................................................... 77
.................................................................. 79
........................................................................... 80
echo print.................................... 81
...............................................................................82
...............................................83
.................................................................... 88
4.
................ .............................................................. 90
.................................................................................... 90
......................................................... 92
.................................................................................... 93
................................................ .93
................................................ 95
........................................................... 96
......................................................................................100
i f .................................................................... 100
e lse ................................................................ 102
e lse if.............................................................. 103
switch...............................................................104
? ....................................................................... 107
.................................................................... 108
w h ile......................................................................109
do...while................................................................ 110
fo r......................................................................... I l l
................................................ 113
continue........................................................... 114
........................................... 114
.................................................... 115
....................................116
................................................................ 117
5. ................................................ 118
...............................................................................119
....................................................... 120
....................................................... 121
......................................................... 123
........................................................... 123
.................................. 125
......................... 125
......................................................... 126
include.............................................................126
indude_once................................ 126
require require_once....................127
........................................................... 127
...............................................................................128
.................................................................... 129
.............................................................130
...............................................................131
............................................................. 131
.................................................................... 134
.............................................................135
........................................................... 136
......................................................... 137
5 ....................... 138
.................................................................... 140
................................................................ 143
6. ...............................................................145
....................................................... 145
......................................... 145
10
......................................................147
, array................ 148
foreach...as......................................................................... 149
. . . .............................................................151
.............................. 154
is_array.............................................................................154
count...............................................................................154
sort.................................................................................. 154
shuffle...............................................................................155
explode.............................................................................155
extract............................................................................. 156
compact........................................................................... 157
reset................................................................................ 158
end.................................................................................. 158
................................................................ 159
7. ................... 160
printf....................................................... 160
......................................... 162
.............................................................. 163
sprintf.............................................165
.............................................................. 165
, ........................................... 167
checkdate....................................... 167
....................................................................... 168
........................................... 168
................................................................ 168
.............................................. ................170
......................................................... 171
........................................................... 171
................................................................ 172
........................................................... 172
....................173
.............................................. 175
-.............................................175
....................................................................... 181
XHTML........................................................................................182
XHTML......................................................... 183
XH TM L.................................................................. 183
XHTML HTML......................................................183
HTML 4.01................................................ 185
i i
HTML5......................................................185
XHTML 1.0................................................ 185
XHTML.............................................186
................................................................ 187
8. M yS Q L......................................................... 188
MySQL.................................................... 188
, ................................ 189
MySQL .............................................. 189
....................190
....................... 193
MySQL................................................................ 195
.................................................................... 199
.................................................................................... 208
...............................................................209
MySQL.............................. 214
......................................................... 223
.................................. 225
MySQL........................................................................... 226
MySQL phpMyAdmin................................................ 226
Windows................................................ 226
Mac OS X ...............................................226
Lin u x.................................................... 228
phpMyAdmin...................................................228
................................................................ 228
9. M y S Q L ........................................................... 230
....................................................... 230
: ...........231
............................................................................. 232
.................................................. 233
.................................................. 235
.................................................. 238
...........................240
................................................................................ 241
................................................................. 241
............................................................... 241
............................................................. 242
.................................................. 244
................................................................................ 244
( ) .................................. 245
BEGIN............................................... 246
12
COMMIT......................................... 246
ROLLBACK....................................... 246
EXPLAIN....................................................247
.............................248
mysqldump..................................... 249
......................................... 250
..................252
CSV .. . ........................... 252
................................ 253
................................................................ 253
10.
13
.............................................286
......................................293
......................................................................294
................................................................ 297
12. Cookie,
.............................. 298
cookie ........................................................... 298
cookie................................................................ 300
cookie................................ ................................. 301
cookie...................................................................301
HTTP-.................................................................... 301
............................. 304
......................................... 305
.................................................................... 308
.................................................................... 309
............................................................... 312
..................................... ....................... 313
.............................. ....................................317
13.
JavaScript........................................................318
JavaScript H TM L.................................................................. 318
...................... 320
.................................. 320
JavaScript.................................................321
JavaScript........................................................322
......................................................... 324
............................................................................. 324
............................................................................... 325
......................................................... 325
......................................................... 326
............................................................................. 326
.................................................................................. 327
.................................................. 327
....................................... ............ 328
......................................................... 328
....................................................... 329
......................................329
.............................................................. 329
....................... ..................................329
.................................................................. 330
.................................................................................... 331
.................................................................331
14
......................................................332
......................................................... 333
........................................................... 335
DOM........................................................... 336
................................................................ 337
14.
15.
15
......................................................367
....................................................... 368
......................................... 369
................................................................ 373
16.
JavaScript ......................................................................... 374
, , JavaScript.. . . 374
validate.html ( )....................................375
validate.html ( )....................................377
................................................................ 380
, ......................... 380
..................................... 381
........................................... 382
............................................................. 383
......................................................384
........................................... 387
....................................................... 388
JavaScript.................. 389
......................... 389
-......................................................................... 390
................................................................ 395
17.
A jax.................................. 397
Ajax?........................................................................... 398
XMLHttpRequest......................................................398
Ajax POST-......................................400
readyState........................................................... 402
Ajax-....................................... 403
GET POST.................................................... 405
XML-................................................................ 407
XML......................................................... 409
XML? ...................................... 410
Ajax ....................................411
................................................................ 412
18.
C S S ............................................................. 413
....................................................414
........................................................... 415
()....................................415
..........................................................415
16
CSS...............................................................................416
.............................................416
.............................................416
.............................................. 417
...............................................................................418
................................................................ 418
..................................................... 418
....................................................419
.............................................................. 419
............................................................. 420
C S S ........................................................................... 420
.................................................................. 420
.............................................................420
.............................................421
.............................................. 422
, ....................... 423
................................................................ 424
.................................................. .
424
....................................................425
........................................................... 426
C S S ......................................................................... 426
....................................................427
...........................................427
....................................................428
<div> <span>..................................................... 430
.................................................................................. 431
................................................................ 433
font-family......................................................................... 433
font-style........................................................................... 434
font-size............................................................................. 434
font-weight..........................................................................435
........................................................... 435
......................................................................436
.......................................................................... 436
.................................................................... 437
................................................................ 437
............................................................................. 437
CSS.............................. ..................................................... 438
..................................... .
438
......................................................................... 439
17
....................................................... 440
.............................................440
....................................... 441
....................................... 441
..................................... 441
............................................................................. 443
......................................................................... 445
445
.................................................. .
....................................................446
................................................................ 446
........................................................... 448
........................................................... 449
......................................................... 451
................................................................ 451
19. CSS C S S 3.............. .............452
.................................................................... 452
.............................................. 453
box-sizing......................................................................454
CSS3.................................................................. 454
background-clip..................................................... 455
background-origin.................................................. 455
background-size....................................................457
......................................... 457
CSS3............................................................................. 459
border-color......................................................... 459
border-radius....................................................... 460
.................................................................... 463
.............................................463
.............................. 464
................................................................ 465
HSL......................................................................... 465
HSLA....................................................................... 466
R G B....................................................................... 466
RGBA . . . ................................................................. 467
opacity................................................................ 467
, ....................................................468
text-shadow......................................................... 468
text-overflow....................................................... . 468
word-wrap........................................................... 469
18
-........................................................................... . . 469
- Google........................................................... 470
........................................................................... 470
.................................................................................. 472
, ....................................473
.............................................. 473
.............................................................473
................................................ 473
..................................................... 474
................................................................ 476
20.
CSS JavaScript...........................................477
getElementByld................................ 477
....................................................................... 477
S ....................................................................... 478
....................................................................... 479
........................................................... 480
CSS JavaScript......................................... 481
.................................................. 482
................................................................ 482
JavaScript.................................................................. 485
th is........................................................... 485
.............................. 486
......................................... 486
....................................................... 487
...........................................................489
.................. 489
...........................................................490
setTimeout..................................... 490
-.............................................................. 491
setlnterval....................................... 491
.............................493
................................................................ 495
21.
...........................................496
...........................................496
-.............................................................497
functions.php....................................................................... 497
........................................................................... 497
header.php............................................................................. 499
setup.php............................................................................. 501
index.php............................................................................. 502
,
1990-,
. (
,
) ,
, .
, - (Tim Berners-Lee) (
)
(Hyper Text
Transfer Protocol (HTTP)). ,
(Hyper Text Markup Language (HTM L)).
, - -.
,
.
,
,
. ,
(bulletin board systems).
- , 1990-
-
, 5 . ,
- . , ,
, ,
HTTP HTML: , -
27
. ,
G IF -.
,
.
, ,
,
.
. ,
. , ,
, ,
.
HTTP HTML: ,
-
HTTP ,
, ,
, -.
,
, -.
(). ,
, ,
-, , .
,
, , . .
. ,
.
- ,
.
.
-
- - -
. (. 1.1).
.
1. http://server.com.
2. IP -, server.com.
3. server.com.
1. -
28
4. - server.com.
5. -, , - .
6. -
.
7. -.
-
server.com
server.com
index
. 1.1.
-
: , - Flash-
CSS.
, 2 IP -,
server.com. , ,
, IP -. , , -
, google.com. , , ,
-,
(Domain Name Service (DNS)),
IP -, .
29
-
, ,
M ySQL (. 1.2).
1. http://server.com.
2. IP -, server.com.
3. server.com.
4. - server.com.
5. -, , - .
6. , , - ,
, P H P -,
.
7. -.
8. M ySQ L-,
, , MySQL.
9. M ySQL
.
10. - ,
, MySQL.
11. - ,
.
,
, ,
.
H T M L-
JavaScript, .
,
, .
, MySQL,
JavaScript CSS
Web 1.0,
Web 1.1,
, Java, JavaScript, JScript ( JavaScript
Microsoft) ActiveX, .
(Common
Gateway Interface (C G I)), , Perl (
), (
).
1. -
30
-
1
MySQL
. 1.2. ,
,
. Perl
,
MySQL
.
A JavaScript, ,
(Cascading Style
Sheets (CSS)),
Ajax- . Ajax (
JavaScript) -
- ,
.
, MySQL ,
?
31
: ,
- . MySQL
, ,
- ,
.
MySQL, ,
Web 2.0.
JavaScript CSS,
-.
,
.
, .
, :
<?php
echo "Hello World. Today is " .d a te ('T ').". ":
?>
How are you?
<?php -
?>. ,
, HTML. How
are you? . P H P- date
, .
:
Hello World. Today is Wednesday. How are you?
PHP ,
PH P- , :
Hello World. Today is <?php echo dateC'l"): ?>. How are you?
,
, . , ,
, - ,
, ,
HTML.
,
vIJ*
, <?php,
------ ?>, .
example.php, .
%
32
1. -
, -
. HTML,
,
-,
PH P-, HTML.
MySQL
, ,
-,
HTML.
,
, .
,
,
. ,
, ,
- - .
. MySQL,
-
, .
,
, .
M ySQL ,
, . ,
, users (),
surname, firstname
email, .
, , :
INSERT INTO users VALUES ( 'Sm ith', 'John',
'jsmith@niysite.com'):
, ,
,
INSERT
. INSERT
(Structured Query Language (SQL)), 1970-
COBOL.
,
.
. ,
.
MySQL:
SELECT surname.firstname FROM users WHERE email='jsmith@mysite.com';
33
JavaScript
, , JavaScript,
H TM L. ,
,
,
? . . (
, -,
). CSS ( ) JavaScript
-, ,
, .
JavaScript ,
, .
,
,
.
,
,
- .
,
.
,
, -
.
34
1. -
, JavaScript,
:
<script type="text/javascript">
document, write ("Hello World. Today is " + DateO ):
</script>
- ,
scrip t, JavaScript,
Hello World. Today is,
, JavaScript
Date. :
Hello World. Today is Sun Jan 01 2012 14:14:00
m%
? *
3?'
: JavaScript, ,
, type="text/javascript"
JavaScript <script>.
, JavaScript ,
, H T M L-, -
. JavaScript
Ajax.
- . ( JavaScript
X M L Asynchronous JavaScript and XML,
.)
Ajax , ,
Web 2.0 ( (Tim O Reilly),
,
), -
, .
Ajax
, ,
, , .
17.
CSS
(CSS3) CSS
,
JavaScript. ,
HTML, , , , , ,
CSS, - .
CSS
<st.yle> </style>, -:
- Apache
35
<style>
P
{
te x t-a lig n :ju stify ;
font-family:Helvetica:
}
</style>
<>,
Helvetica.
18 ,
CSS
, .
HTML.
, , , hover
. ,
CSS- JavaScript
HTML.
- Apache
, MySQL, JavaScript CSS -
-. ,
- Apache. , -
HTTP,
.
, Apache H T M L-
, Flash-
MP3, RSS- (Really Simple Syndication
) . . , HTML -, ,
.
,
G IF -. ,
. :
, , ,
. ,
Apache ,
. G D (
Graphics Draw - ),
.
Apache .
-
, .
Rewrite, -
36
1. -
U R L -
, Proxy,
,
.
,
.
, ,
, , MySQL Apache
.
,
,
,
.
.
:
. -
,
.
,
.
,
, MySQL, JavaScript CSS
,
-: -, MySQL
, CSS JavaScript
-. JavaScript P H P -
-, - ( ,
).
, ,
, , ,
-
Ajax: ,
- .
Gmail (. 1.3).
file
dit
https://accounts.go...
View
Favorites
Tools
37
Google Accounts
Help
Name
Samuel
Smith
samsmith
smithsamuel169 ss1676073
Create a password
-- ---- ---
:....
<^100% ^ ,
. 1.3. Gmail Ajax
Ajax- .
1. H T M L -,
: , ,
.
2. HTM L JavaScript,
: -
.
3.
, JavaScript
P H P - - .
4. - JavaScript
, , .
5. JavaScript
, ,
, .
6. ,
, JavaScript
(,
/ )
.
7. ,
,
.
38
1. -
.
Ajax , HTML
, . , ,
,
.
Ajax
, .
,
Ajax.
, MySQL, JavaScript CSS (
Apache) . 2
, -
, .
.
1.
-?
2. HTML?
3. M ySQL SQL?
4. JavaScript ,
-.
?
5. CSS?
6.
( ), , -,
?
,
1.
-,
, ,
, ,
- .
.
(
) Refresh
() .
,
,
- , , ,
. ,
, , ,
()
.
, ,
, .
, ,
, -
Linux-.
, 1. ,
, JavaScript CSS,
-,
.
Internet Explorer, Mozilla Firefox, Opera, Safari Google Chrome.
, ,
Apple iOS Google Android.
40
2. ,
WAMP, LAMP
WAMP, LAMP Windows, Apache, M ySQL ,
, Apache, M ySQL Linux, Apache, M ySQL .
,
-.
WAMP, LAMP ,
,
. ,
, .
.
,
-, ^
.
.
-
.
W/L/MAMP,
,
.
, , .
WAMP Windows
W A M P-,
. ,
Zend Server ( Community Edition
),
. - http://tinyurl.com/zendce (. 2.1).
(
5.6.0 SP1 Windows), -
. ,
: Linux, Windows OS X.
. ,
,
.
<4-*
V ?--
------------------------------------------------------------
, , , , . ,
, .
4
WAMP Windows
41
Edit
View
Favorites
Tools
Help
j
ii
Server CE
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
IBM only,
for 1 year
0 Linux
Windows
ti*-. Mac OS X
Product
Version
Format/Size
Notes
5 6.0 SP1
i'EXE)
Release Notes
58 23 MB
ji
, ,
. 2.2.
Next () ,
(Setup ) (. 2.3).
Custom ( ),
MySQL.
(Custom Setup),
,
phpMyAdmin MySQL Server (. 2.4). Next
().
(. 2.5), - IIS,
- Apache,
.
Next ().
80 - 10081 Zend (. 2.6)
Next ().
2. ,
server
lrr,!s89w*l
"<eack
. 2.3. Custom ( )
WAMP Windows
Custom Setup
S elect com ponents to install
- - -----
-----------------
: L J Z e n d J a v a B tia g e
- Description---->
; D D o i o (se p a ia te d ow nload)
Informix
0 O r a d e O C I D river
@ phpM yA dm in I sep arate d o w nload!
1 D l B M D B 2 R T C L (se pa ra te d o w n lo a d l
. 2.5. - Apache
2. ,
44
Zv -
server
Number
Click Next tc>use the default settings or change the port values that your Webserver will listen
and that the Administration Interface uses respectively
(10081
Ins-fcaRStesJd
OK
Ne>:( >
cl-
Cancel
. 2.6.
, . 2.7,
Install ().
,
.
, , Finish ()
.
,
, . 2.8.
, .
(. 2.9). ,
, Next () ,
. 2.10. Finish ().
.
4
----
- , ( -),
, 8080 ( 8000) -
10082 Zend.
, -, Zend. ,
- http://localhost/index.htm, http://
localhost:8080/index.htm.
WAMP Windows
45
5.39
Common Extensions
Additional Extensions
Zend Optjmeef+
Zend Debugger
Zend Data Cache
Zend Page Cache
Zend Monitor
Zend Job Queue
Zend Session Clustering
Zend Code Tracing
Zend Deployment
Zend Framework 1.11.11
Zend Framework Base
<
r-
. 2.7. Install ()
-.............
.....
..
__
__
I have read and agree to the end user license agreement terms
^811111118!81811111!1811888181
<*U0Q% *
. 2.8. Zend Server CE,
46
2. ,
Step 2 of 3
Set Password
Enter P .v 'vA'or-i
................
Retype P;r,*v*or'J
.............,)
. 2.9.
...
...
Http://localhostl00Bl/ZendServer/Loginsl3=
ifile
Edit
View
Favorites
Toots
^
<
Help
Welcome to
Zend Server Community Edition!
Thank you for installing Zend Server Community Edition - you've made a great choice!
If you ever want to enhance your PHP environment with:
Automated deployment
Perfoimance optimization
Application monitoring
You can try the advanced features of Zend Server free for 30 days at any time!
" ^Modify me of new ZendSetver Community Edition releases arid other important!
jjp dates
Email Address I
. 2.10. Finish ()
Dashboard ( ),
(. 2.11).
WAMP Windows
47
,
http://1 Ihost:10081 (,
Zend , 10081,
, ).
, .
-,
(. 2.12). U R L -
:
http://local host
http://127.0.0.1
1 1host U R L -
, 1- 127.0.0.1,
- .
^--1
, 80 ( 8080),
J URL-
. : http://localhost:8080.
. , URL http://localhost/example.php, http://
localhost:8080/example.php ( , ).
2. ,
48
- sex
http://127jQ.0X'1'
File
fd it
Yiew
Fjrvorites
Jools
**
Help
zend
. 2.12.
,
- . ,
U RL , http://yahoo.com http://
localhost.
Zend Server
( 32- ,
64-):
:/Program F i 1es/Zend/Apache2/htdocs
:/Program F ile s (x86)/Zend/Apache2/htdocs
pt^r*%
, , 32- 64-,
d l, . , , 32- . ,
, 64- .
, , ,
Hello World. H T M L, , Windows-
(
, Microsoft Word, ,
):
49
WAMP Windows
<html>
<head>
<title>A quick test< /title>
</head>
<body>
Hello World!
</body>
</html>
,
, t e s t . htm.
, ,
, (*.txt).
,
U R L- (. 2.13):
h ttp ://1 !host/test.htm
Fife
fdit
http://localhost/te5thtm P <$ X
View
Favorites
Took
A quick test
ft?#
Help
Heflo World!
^ 100% .
. 2.13. -
WAMP. ,
, http://tinyurl.com/zendcedocs.
WAMP
- .
Zend Server ,
,
.
, ,
, W AM P-,
, .
, , :
EasyPHP: http://www.easyphp.org;
: http://apachefriends.org/en/xampp.html;
50
2. ,
WAMPServer: http://wampserver.com/en/;
Glossword WAMP: http://glossword.biz/glosswordwamp/.
Mac OS X
Zend Server OS X. h ttp ://
tinyurl.com/zendce (. 2.14).
support
monitoring and code tracing
Yes
Zend. Sfirver.Glygtef.Manager
support
Yes
Yes
hotfixes
orty.
for 1 year
IBM i
Note: Zend Server CE for the Mac OS X platform is meant for development use only, not production use.
Product
Version
Format/Size
Notes
(OMG) 152.90 MB
Release Notes
(
5.6.0 SP1 OS X), -
.
: Linux, Windows OS X.
.
,
.
Mac OS X
51
, DM G.
, ,
. 2.15. ,
READ ME. Zend Server ( Zend) Zend Controller
( Zend) Applications, Go (
) Finder, .
z e n d 'S e r v e r
Community Edition
Zend Server
RTF
README
11
To Install Zend Controller, drag the
icon to your Applications folder
. 2.15. Applications ()
52
2. ,
6 Introduction
Read Me
Destination Select
Installation Type
Installation
Summary
_.
_
Community Edition
Go Back
-----------------------------
[ Continue
' -----------------------------
I
>
0 Introduction
Read Me
6 Destination Select
6 Installation Type
Installation
# Sum mary
Community Edition
Co Back
Install
~)
. 2.17.
,
Applications Zend Server .
, , ,
Mac OS X
53
. 2.8. , . 2.8-2.10,
,
.
.
MySQL
, Zend Server ,
, , MySQL,
,
Terminal :
sudo nano /usr/1ocal/zend/bin/zendctl.sh
Nano,
, MySQL_EN=" fa l se" , false
true.
, :
case $1 in
"start")
, :
SO start-apache
, :
$0 start-MySQL
MySQL . ,
, :
"restart")
, :
$0 restart-apache
:
$0 restart-MySQL
MySQL, .
MySQL, ,
:
"stop")
:
SO stop-apache %
:
$0 stop-MySQL
54
2. ,
Ctrl+X
. , ,
Return .
MySQL
M ySQL -,
Terminal :
cd /Library/StartupItems/ZendServer_init/
sudo rm zendctl.sh
sudo In -s /usr/local/zend/bin/zendctl.sh ./
Mac , MySQL .
, :
sudo /Library/Startupltems/Zend5erver_init/zendctl.sh restart
U RL
, . 2.18:
http ://localh ost:10088
http://127.0.0.1:10088
localhost ,
1- 127.0.0.1. , : 10088
, - -:
.
: 10088 http://localhost ,
. , tes:
URL http://localhost:10088/test.php.
, Mac-
* -, (
- * ), /usr/local/zend/apache2/conf/httpd.conf.
Listen 10088 ( 40)
Listen 80.
, Terminal : sudo
/usr/local/zend/bin/zendctl.sh restart.
:10088 URL-.
, http://localhost
http://localhost:10088, index, html,
,
- . ,
U R L - , http://yahoo.com,
- http://localhost.
Mac OS X
55
. 2.18. -
Zend Server
:
/usr/local/zend/apache2/htdocs
, ,
. , , TextEdit (
, Microsoft Word,
, ) H T M L, :
<html>
<head>
<title>A quick test< /title>
</head>
<body>
Hello World!
</body>
</html>
, test.htm.
2. ,
56
U R L (. 2.19):
h ttp ://lo ca lh o st:10088/test.htm
. 2.19. , ,
.
, http://tinyurl.com/zendcedocs.
I
%
------------------------------------- !----------------------------------------------------------------------
URL-, ,
- tinyurl.com. , http://tinyurl.com/zendcedocs
, URL-, : http://files.zend.com/help/ZendServer-Community-Edition/zend-server-community-ed ition.htm.
LAMP Linux
, ,
Linux-. Linux,
LAM P .
Linux - MySQL,
, . ,
, ,
-, :
http://localhost
, , , Apache,
MySQL,
,
.
- , Zend Server
, http://tinyurl.com/zendce.
57
.
, ,
.
-,
MySQL, -.
,
. , ,
.
MySQL.
Telnet SSH. , -,
, ,
M ySQ L ( , ,
).
Windows Telnet SSH (
, SSH , Telnet)
PuTTY, http://putty.org.
SSH .
Applications, Utilities,
Terminal. , SSH
:
ssh mylogin @ server.com
server . , , a mylogin
, .
, ,
.
FTP
- FTP-.
, ,
.
FireFTP,
:
2. ,
58
- Firefox
, ;
, ;
FTP- ,
- .
&
: Microsoft Internet Explorer, a FireFTP
. , , -,
,
.
FireFTP - http://fireftp.mozdev.org,
Firefox, Download FireFTP ( FireFTP).
500 .
Firefox,
FireFTP Tools () (. 2.20).
t
Bookmarks Jools
j ^
Help
chrome//fireftp/coritent/fireftp.xul
P\
* Coogis
| Log/Queu<| loots )
- ' Change
-a&lpmj.net
>10
>11
12
>13
1>14
(15
)16
{Q17
Name
Ljl-php
p lO .p h p
Size
ak3lpmj.net
Date
> O io
(jll.p h p
Q l2 .p h p
2 KB
LJl3.php
p l4 .p h p
t>CDU
12
> D i3
,. Mar 19 2011
Ljl5 .p hp
3 KB
[Jl6.p h p
L)17.php
>C)20
>CJ4
Q ie .p h p
)l9 .p hp
2.php
>C)4
L)3.php
>05
p4php
Q s .p h p
p 6 ,p h p
>06
>07
p 7 .p h p
>09
Q e .p h p
-*-
O l8
> Q l9
7
t>CD8
>09
l E 3__
Lj20.php
... . .....
.. Mar 19 2011
>>16
17
18
@D
Q l 9
20
>08
l>Qe
__
Name
L jl.p h p
2KB _
Mar 19 2011
lO.php
4KB _
Mar 19 2011
[ j 11.php
p l2 .p h p
Q l3 .p h p
2 KB _. Mar 19 2011
2KB _ Mar 19 2011
P 14. php
2 KB
L jl5.php
Mar 19 2011
L j l^.php
[ J 17.php
2 KB
p l8 .p h p
2 KB
2
L j 19.php
U 2.php
. Mar 19 2011
Mar 19 2011
Mar 19 2011
2 KB
Mar 19 2011
|_]20.php
Lj3.php
3
3KB
Q 4 .p h p
4 KB ..
Mar 19 2011
Mar 19 2011
p 5 .p h p
4 KB ..
Mar 19 2011
Mar 19 2011
L]6.php
3KB
Mar 19 2011
[_j7.php
Q 8 .php
4 KB - Mar 19 2011
3*T> _ u .n u a iJ L
....
Log [.Queue I
Local listing: 62 object(sX 521 MB. Disk Space Available: 8 GB
Binary
FTP- FileZilla,
http://filezilla-project.org Windows, Linux Mac OS X 10.5
.
, FTP-, .
59
HTML, , JavaScript CSS
, ,
,
, .
, .
, ,
.
,
Editra, Mac OS X,
Windows Linux/Unix (. 2.21). , -
http://editra.org Download () ,
.
*examples.php - file//C:\Users\Robin\Desktop\examptes.php - Editra vO.6.99
Fite |dit
View
Fgrmat
gettings
Toob
jjd p
$contents * 0file_get_contents($page);
if (!$contents) return FALSE;
$checksun. = iad5 ($contents) ;
if (file_exlats($datafile))
m
$rawfile
$data
$left
rigbt
=
=
*
=
file_get_contents($datafile);
explode("\n", rtrim($rawfile));
array_ap{nPU_Fln,
$data);
array_map ("",
$data);
$exists
= -1;
for ($j
0 ; $j < c o u n t ($left)
; ++$j)
{
if ($left[$]
$page)
{
$exists = $ j ;
if ($right[$3 J
>
PHP
cpl252
CRLF
. 2.21. Editra
Editra , ,
. , Editra
,
. Editra
, .
60
2. ,
IDE
,
,
(Integrated Development Environment, IDE),
,
,
.
. 2.22 phpDesigner
, ,
Code Explorer, ,
, .
\Q
? v d
fib
il foWa
Debug Project Tools Svn (St Highlighters View Window Help : Trial expires in 21 days
>\\
j0DCphp]_:
CodeExpkiref
2847
2848
2849
2860
2851
2052
2853
2854
2855
2056
2857
2858
2859
2660
2861
2862
2063
4
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
if (Stcolor)
if (Stsize)
(Slabela)
(Slegends)
(Scolors)
(Sbgfill)
if
if
if
if
Surl
h)
Stall
Stall
Stall
Stall
Stall
AutoBad<ljnfcs($f3ename)
6-
; S-
BBCode($rtmQ)
EloddUseyCootae{$act>on, $hande, Sexpre)
BBypassCapteheO
B-fiCapsContrQK$*e*t,Stype)
- A ChedcCapttha($captiha, $tofeen, $ea<U, $salt2)
Q C hed4r*s(Spagef Stmeout, $rurtrne)
"http://chart.apie.google.com/char t?j||!";
chart in-ag*
| E&- Q OoseSessonO
! ~
ConvertCurrency($aniount, $from, $to)
i S ] ) ComerGrf($CDmer, {border,
: e |]auitTrf($uito)
j - Q
: ()- ^
! -
CuriGetContents($Lrl/ Sagent)
j -
j Q
OrectDryOaKSpath)
ttsptovBngMap($tat, $ong, Sroora, Sstyte,
I f flb r t o e d y o u T i* e V k ie o ( $ d , * {height,
; G9- Q EvakjateExpressondexpr}
|
!
ID E ,
( ),
.
,
ID E ,
.
61
,
. ,
. . 2.1
P H P - U RL-,
.
2.1.
IDE
URL-
W in
Eclipse PDT
Mac
Komodo IDE
http://activestate.com/Products/komodo_ide
$245
Linux
NetBeans
http://www.netbeans.org
phpDesigner
http://mpsoftware.dk
$39
$119
PHPEclipse
PhpED
http://phpeclipse.de
http://nusphere.com
PHPEdit
http://phpedit.com
$119
Zend Studio
http://zend.com/en/downloads
$395
ID E , ,
- ,
, .
, ,
.
IDE,
3,
H T M L , . ,
, ,
.
1. WAMP, LAMP?
2. 1- 127.0.0.1 URL- http://localhost?
3. FTP-?
4. -.
5. ,
?
,
2.
1 ,
,
-. ,
, 6.
(ID E ), 2. ,
,
.
ID E , ,
.
HTML,
- ( ,
).
- ,
HTML, JavaScript, MySQL CSS.
, ,
.
.
P H P -
.
HTML
P H P - .
- ,
P H P -. -
, - ,
P H P -
HTML. ,
.
,
-.
HTML
63
HTML. ,
H T M L-, index.html,
i ndex.php, , .
.
:
<?php
, , .
, .
, , :
?>
P H P - Hello World ,
3.1.
3.1.
<?php
echo "Hello world":
?>
.
, HTML
.
, ,
,
HTML.
, ,
, ,
.
, ,
, ,
, HTML
, - .
,
PH P - , ,
:
<?
echo "Hello w orld":
?>
P H P -,
, , , .
64
3.
, X M L
( ,
).
&
^*.*1*
, ?> .
,
( - ).
4
f
,
, ,
- http://lpmj.net, 2nd_eci t i on_
examples .zip, Download Examples ( ),
(. 3.1).
1
| |
Eil
Edit
http://lpmj.nrt/
View
Favorites
Xools
~ 8
l -
X L g J
Help
By Robin Nixon
Home I >
Find out for yourself why Learning PHP ; MySQL & JavaScript is the number-one best-selling blockbuster
that has been at the top o f the charts for over two years worldwide, is the first result returned on PHP by
Amazon US, UK and Canada, the first foreign language title on PHP returned on European Amazon websites,
and in the top 10 foreign books on PHP on Amazon Japan and China!
Learning PHP, MySQL A JavaScript will teach you how to create responsive, data-driven websites with
the three central technologies of PHP, MySQL and JavaScript - whether or not you know how to program. This
simple, streamlined guide explains how the powerful combination of PHP and MySQL provides a painless way
to build modern websites with dynamic data and user interaction. You'll also learn how to add JavaScript to
create rich Internet websites and applications, and how to use Ajax to handle background communication with
a web server.
PHP, MySQL
& JavaScript
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Introduction to PHP
Expressions and Control Flow in PHP
PHP Functions and Objects
PHP Arrays
Practical PHP
Introduction to MySQL
Mastering MySQL
Accessing MySQL Using PHP
Form Handling
Cookies, Sessions and Authentication
Exploring JavaScript
. 3.1. , , http://lpmj.net
(,
example3-l. php). , examples. zip,
named_examples, , -
65
(
3.4, t e s t l . php).
.
,
,
. , ,
, .
. ,
,
:
//
,
. ,
, ,
:
// echo "X equals $";
,
:
$ += 10: // $ 10
, ,
,
3.2.
3.2.
<?php
/*
-: *.
6yze~
/ */
?>
/* */ .
,
,
.
3.
66
/* */ ,
, ,
. ,
PHP- , ,
.
,
.
, Perl,
Java. , ,
, .
,
:
$ += 10;
, ,
, . ,
,
Parse error.
$
$ .
, BASIC $
, , .
$ .
, P H P - , ,
. ,
, , ,
3.3.
3.3.
<?php
Smycounter = 1;
$mystring = "Hello":
Smyarray
= arrayC'One". "Two". "Three"):
?>
, , , .
, Python,
, (
) .
,
67
, ( ),
,
.
, .
, , . ,
( ) !
, .
, , username (
). Fred Smith
(. 3.2).
:
$username = "Fred Smith":
. 3.2. ,
, Fred Smith .
,
().
, .
, , ,
, .
:
echo $username:
3.
68
(
):
$current_user = Susername:
,
, ,
( , 2),
, 3.4
( 2)
t e s tl. php.
3.4. -
<?php // testl.php
$username = "Fred Smith":
echo Susername:
echo "<br />";
$current_user = Susername:
echo $current_user:
?>
:
http://localhost/testl.php
nr
--1 ------------------------------------------------------------~
- ( 2)
V? - , 80,
9?*' URL . ,
8080, URL :
http://localhost:8080/testl.php
.
Fred Smith,
echo Susername,
echo $current_user.
, .
, Scount 17
, , 17 ,
count:
Scount = 17:
(
); :
Scount = 17.5:
69
,
. Scount
- , echo.
. ,
Steam. ,
.
team
(. 3.3). :
Steam = array( ' B i l l . 'Joe',
'Mike'.
'C h ris'.
'Jim');
. 3.3.
.
:
;
.
.
, 4,
:
echo $team[3]; // Chris
3, 4 ,
P H P - , , ,
0 4.
70
3.
. ,
,
.
, ,
-, ,
, 3 4 3.
, , ,
(. 3.4).
. 3.4. ,
. . ,
, 3.5.
.
3.5. ^
<?php
Soxo = array (( . ,
a rra yC o '. ' ',
arra yC x '. ' ',
?>
' '),
).
" ));
, ,
. array !;
=
.
>4 PHP-, ^ ** :
71
, ( ) , , [1]
J o , [2]
*.' .
.
, ,
.
.
6.
P H P -
.
_ (
).
: a-z, A-Z, 0-9, _ (
).
.
,
(,
$user_name).
. $Hi gh_Score
$high_score.
, ,
, , , .
. ,
8:
echo 6 + 2 :
,
.
. .
(, ,
), ( )
(. 3.1).
72
3.
3.1.
$j + 1
$ j- 6
$j * 11
$ j/4
( )
$j % 9
++
()
++$j
--
( )
.
=, +=, -= . . (. 3.2).
+=
, . , Scount
5,
Scount += 1;
Scount 6 ,
:
Scount = Scount + 1;
3.2.
$j = 15
$} = 15
+=
$j+ = 5
*
II
$j /= 16
$j = $j / 16
.=
$j .= $k
$j = $j $k
%=
/=
SP
II
SP
*=
II
00
CO 00
1 *
S?
II
II
CO
I1
I
-=
5:
+
, (.),
.
, ,
i f, .
, , ,
, -
. . (. 3.3).
73
3.3.
==
!=
!= 21
>
$j >
<
$j < 100
>=
<=
II
V
Lf)l 00
i
II
A
, = == .
, .
, , .
,
- . ,
. , :
12, 14 , , .
:
i f ($hour > 12 && Shour < 14) dolunchO:
do! unch,
. then
(), .
,
,
.
(
12, 14 ,
...). , -
TRUE FALSE,
,
.
. 3.4.
3.4.
&&
$j == 3 && $k == 2
and
$j == 3 and $k == 2
II
or
!
$ j< 5 11 $j > 10
$j < 5 or $j > 10
! ($j == $k)
xor
$j xor $k
74
3.
, && and;
11 . and or
, ,
, .
, and or,
, or ( 10):
mysql_select_db($database) or die("HeB03M0H0 "):
,
, TRUE,
, FALSE,
TRUE FALSE. ,
, . (ammonia),
(bleach) , ,
.
, .
:
$ingredient = Sammonia xor Sbleach:
, Sammonia
$bl each, TRUE, Si ngredi ent
TRUE. TRUE FALSE,
Si ngredi ent FALSE.
=
.
= .
,
. , :
$ += 10:
- ,
( 10), $.
:
$ -= 10:
, .
+= -= :
++$:
-$:
75
( i f)
:
i f (++$ == 10) echo $:
$
, , 10;
, .
(, ,
) , :
i f ($-- == 0) echo $;
. ,
$ .
TRUE, , ,
$ -1. echo: 0 -1 ?
, , ,
P H P -.
, ,
.
,
, , ,
, .
, : echo
-1, $
, i f , ,
echo.
, ,
(.).
:
echo " " . Smsgs . " .":
, $msgs 5,
:
5 .
, +=
, .= :
Sbulletin .= Snewsflash;
, $ b u lle tin ,
Snewsflash ,
$bul 1e ti
.
76
3.
,
. ,
,
():
Sinfo = ' $. : Svariable';
$i nfo ,
.
, Svari abl .
, ,
, :
echo " Scount
,
,
.
. ,
, .
,
, . ,
, (),
sis te r s, PH P - , .
, :
Stext = 'My s is te r's car is a Ford : /7
,
,
:
Stext = 'My s is te r V s car is a Ford':
,
, . ,
, ,
:
Stext = "My Mother always said V'Eat your greensV'.";
, ,
, ,
\t, \ \. ,
(
,
-):
Sheading = "";
77
, ,
, .
,
\t. ,
,
( \') (\\).
,
echo ( print), .
, ,
.
, 3.6.
, 3.7.
3.6. echo,
<?php
Sauthor = " ";
echo "
.
.
Sauthor.";
?>
3.7.
<?php
Sauthor = " ";
Stext = "
.
.
Sauthor.";
?>
,
<, here-document ( )
, , heredoc.
,
( ). 3.8.
3.8. echo,
<?php
Sauthor = " ";
echo < END
3.
78
.
.
- Sauthor.
_END;
?>
,
_END, , .
, , , H T M L-
, .
, END:
(
). ,
.
: heredoc- <<<_END..._END;/
\, , S Enter . ,
, heredoc
,
(\).
3.9 ,
.
3.9.
<?php
Sauthor = " ":
Sout = <_END
.
.
- Sauthor.
_END;
?>
Sout ,
. , ,
Sout =
.=.
, END,
Parse error.
79
END,
.
, END , ,
- .
, _SECTI0N1 _
OUTPUT . . , ,
; ,
.
,
, -,
HTML (
$author -
).
, , ,
,
. ,
, ,
.
. ,
,
.
, , ,
- , , .
( 3.10) 12 345 67 890
838 102 050, Snumber.
3.10.
<?php
Snumber = 12345 * 67890;
echo substr($number, 3, 1);
?>
, Snumber .
-
substr, Snumber ,
( , ).
Snumber ,
, substr
, 1.
. .
3.11 Spl ,
3.
80
,
,
78,5398175.
3.11.
<?php
$pi = 3.1415927";
Sradius = 5;
echo $pi * (Sradius * Sradius);
?>
,
. , ,
. , ,
, , echo.
, , ,
, ().
,
.
,
(,
-). :
define("R00T_L0CATI0N . "/us /1 1/www/");
,
( ):
Sdirectory = R00T_L0CATI0N;
, P H P -
, .
--1
%
? J *
:
$ ( ) define.
,
- .
,
, , .
, ,
.
81
,
.
. 3.5. , ,
.
3.5.
_LINE_
_FILE_
.
include, .
4.0.2,_FILE_
,
_DIR_
. include,
.
dirname(_FILE_).
,
. ( 5.3.0)
_FUNCTION_
. 5, ,
( ). 4
. ( 4.3.0)
_CLASS_
. 5, ,
( ). 4
.
( 4.3.0)
_METHOD_
. ,
( ). ( 5.0.0)
_NAMESPACE_
( ).
. (
5.3.0)
, ,
, :
echo " " . _LINE_ . " " . _FILE_:
-
, ( ).
echo print
echo
. ,
. , .
echo , :
pri nt. , print
, , a echo
.
82
3.
, echo print,
.
, , , pri nt,
.
, (TRUE)
(FALSE), pri nt,
echo ,
Parse error:
$b ? print "TRUE" : print "FALSE":
,
$, . ,
, , $
, , , , $
.
echo, , - pri nt.
,
. , -
, . ,
, ,
,
.
, ,
.
,
( ),
,
. .
, , 3.12.
3.12.
<?php
function longdate($timestamp)
{
return dateC'l F jS Y", Stimestamp);
}
?>
Unix ( , ,
1 1970 ), P H P - date
83
,
1 2016.
,
. ,
, .
,
:
echo longdate(timeO):
Unix
1ongdate,
echo, -
time. ,
:
echo 1ongdate[i ' () - 17 * 24 * 60 * 60):
I ongdate Unix,
, 17 (17 24 * 60 * 60 ).
, ,
.
,
, , ,
. , , , ,
$temp ,
, -
.
.
,
.
. ,
.
. ,
Stimestamp.
, ,
.
,
longdate ( 3.13).
84
3.
3.13. longdate
<?php
function 1ongdate(Stimestamp)
{
$temp = dateC'l F jS Y", Stimestamp);
return ": Stemp";
}
?>
, date,
Stemp, ,
. ,
Stemp , .
, ,
, 3.14. Stemp
1ongdate.
3.14. Stemp
longdate
<?php
Stemp = ": ";
echo longdate(timeO);
function longdate(Stimestamp)
{
return $temp . dateC'l F jS Y , Stimestamp):
}
?>'
Stemp 1ongdate,
, longdate
.
. ,
(Noti : Undefi ned
variable: temp).
, , ,
, ,
, ,
.
3.15 3.16 ,
3.14.
3.15. Stemp
<?php
Stemp = ":
echo Stemp . longdate(timeO);
function longdate(Stimestamp)
85
}
?>
3.15 Stemp .
, .
3.16. :>5 : Stemp
<?php
Stemp = ":
echo 1ongdate($tenr. : ' T5());
function longcaie.S.eA*. Stimestamp)
{
return Stext . caie-." F jS Y". Stimestamp):
}
?>
3.16 : Stemp
1~~ . longdate
,
Stext, .
*
*&~
, , ,
,
*** . , , , :
, ,
, ,
, .
, ,
, , .
,
.
, ,
global. ,
-, , ,
.
Si s_l ogged_i n:
global $is_logged_in;
1,
0. ,
.
86
3.
.
,
. - ,
, .
( -
) , - ,
, ?
, ,
, , , ,
.
.
4
----
------------------------------------------------------------
* ( ), .
,
.
,
.
, , ,
,
? ? ,
, , .
, 3.17,
.
3.17. ,
<?php
function test
{
s ta tic $count = 0;
echo Scount;
$count++;
}
?>
$count, .
,
.
, Scount
,
Scount .
87
, ,
- .
( 3.18).
3.18. v
<?php
s ta tic $int = 0:
sta tic Sint = 1+2:
i~
-e::-..
:5:::5
(
D5rse error))
4.1.0.
. .
.
,
.
(. 3.6).
, 6.
..
$GLOBALS
,
.
$_SERVER
, , .
-,
, - -
$_GET
,
HTTP GET
$_POST
,
HTTP POST
$_FILES
, HTTP POST
$_COOKIE
, HTTP
cookies
*
$_SESSION
$_REQUEST
, ;
S_GET, S_POST $_1
$_ENV
, environment
( )
, ,
, ,
.
88
3.
, .
,
, U R L - ,
-.
:
$came_from = $_SERVER[' HTTP_REFERRER ];
, .
, U R L- ,
$came_f .
,
,
-. S POST, $_GET
, Unix MySQL,
, ,
.
.
P H P - htmlentities.
HTML. , (< >)
& lt; >,
, . .
$_SERVER ( ) :
$came_from = htm lentiti es($_SERVER['HTTP_REFERRER ]):
, .
4
, ,
.
,
, ,
.
1. ,
? ?
2. ?
3. ?
4. ?
89
5. ?
6. Svariable = 1 Svariable == 1?
7. ,
($current_user), (Scurrent-user)?
8. ?
9. ?
10.
(, )?
11. ++$j $j++?
12. && and?
13. : echo
?
14. ?
15. ?
16. echo pri nt?
17. ?
18. -?
19. ,
?
20. ?
,
3.
,
, ()
. 3
,
.
,
.
.
.
, . :.
,
, - : :
= 3(abs(2x) + 4)
:
$ = 3 * (abs(2*$x) + 4);
( $) .
( . 5!:*:
X IX ).
, , .
~_.
FALSE. , 21 > *(20 9) (
5 == 6 (5 6) (-_5). (, .
, 11.11
91
, AND, O R XOR,
.)
, TRUE FALSE
. ,
. ,
,
. , , ,
, , ,
, ,
.
4.1 : ,
, .
d, ( < />
H T M L
).
4.1.
<?php
echo "a:
echo "b:
echo "c:
echo "d:
?>
:
: [1]
: []
: []
d: [1]
, , : d:,
(TRUE), 1.
: : (FALSE) ,
FALSE NULL ().
, , 4.2.
4.2. TRUE FALSE
<?php // te st2 .php
echo "a: [
TRUE
"]<br />"
echo "b: [" . FALSE . "]<br /> ;
?>
:
: [1]
: []
, FALSE 0
-1, .
4.
92
, ,
, 73 Hello.
,
. ,
.
4.3 ,
, .
4.3.
<?php
Smyname = "Brian";
Smyage = 37;
"<br
echo "a: " . 73
"<br
echo "b: "
"Hello"
"<br
echo "C: " . FALSE
echo "d: " . Smyname ., "<br
echo "e: " . Smyage . "<br
?>
/>":
/>";
/>";
/>";
/>":
//
//
//
//
//
,
, ;,
FALSE :
:
b:
:
d:
:
73
Hello
Brian
37
,
, -
.
. 4.4
.
366 - $day_number $days_to_new_year,
, $days_to_new_year < 30
TRUE.
4.4.
<?php
$days_to_new_year = 366 - $day_number;
i f ($days_to_new_year < 30)
//
{
echo " !":
}
?>
//
93
, ,
,
(. 4.1).
4.1.
$ + $
$ + $
$ = $ + 23
12 9
$ < $
'Is -
$++
$ and $b
$ . $
.
, ($++)
(-$), .
, ,
, , ,
.
0 , ? : z. ,
i f,
,
. .
,
, .
,
4.5.
4.5.
1 + 2
2 - 4
5 + 2
+3 - 4 + 5
+5 + 3 + 1
-4 +1 + 3
94
4.
, , (
), 7,
.
( 4.6).
4.6. ,
L * 2 * 3 / 4 * 5
2 / 4 * 5 * 3 * 1
5 * 2 / 4 * 1 * 3
7,5. ,
,
4.7.
4.7. ,
1 +2 * 3 - 4 * 5
2 - 4 * 5 * 3 +1
5 + 2- 4 + 1 * 3
,
25, -29 12 .
,
, ,
, 4.8.
4.8. ,
1 + (2 * 3) - (4 * 5)
2 - (4 * 5 * 3) + 1
5 + 2 - 4 + (1 * 3 )
, ,
, , 4.9.
4.9.
1 + (6 ) - (20 )
2 - (60) + 1
5 + 2 - 4 + (3)
-13, -57 6 ( 25, -29 12,
).
, ,
, ,
, (
4.10).
4.10.
((1 + 2) * 3 - 4) * 5
(2 - 4) * 5 * 3 + 1
(5 +'2 - 4 + 1) * 3
95
, , 25, -29 12
.
. 4.2
.
4.2. , ( )
()
0
++ -!
* /%
+-
<< >>
<<=>> =
1-------|
&
( )
1
&&
II
?;
and
xor
or
,
, .
.
.
,
. . 4.3 ,
.
4.3. ,
NEW
j
++ "
&
96
4.
4.3 ()
+-
(nt)
(double)
(string)
(array)
(object)
, 4.11,
0.
4.11.
<?php
--1 ------------------------------------------------------------
4 3?' , . ,
, , .
, TRUE, FALSE.
: , .
== ( )
. = (
). 4.12 ,
.
4.12.
<?php
Smonth = "";
i f (Smonth == "") echo " ";
?>
97
, TRUE FALSE,
, i f . ,
.
, ,
.
, , ,
. 4.13 $ $
, , -
i f .
4.13.
<?php
$ = "1000";
$b = "+1000":
i f ($ == $b) echo " I ;
i f ($ === $b) echo "2";
?>
, , ,
i f TRUE. ,
, 1000 , +1000.
, i f
,
. $ $
,
.
,
, ,
.
,
, !=.
4.14 4.13,
.
4.14.
<?php
$ = "1000";
$b = "+1000";
i f ($ != $b) echo "1":
i f ($ !== $b) echo "2";
?>
, , , i f 1,
$ $. 2, i f
$ $,
TRUE, .
98
4.
, ,
.
> (), < (), >= ( ) <= ( ).
4.15 .
4.15.
<?php
$ =2: $ = 3;
i f ($ > $b) echo "$
i f ($ < $b) echo "$
i f ($ >= $b)echo $
i f ($ <= $b) echo "$
$b<br />";
$b<br />";
$b<br />":
$< />";
?>
, $ 2, $
3, :
2 3
2 3
,
$ $, .
, .
,
. (. 4.4).
4.4.
AND
(TRUE),
OR
(TRUE),
XOR
(TRUE),
NOT
(TRUE),
, (FALSE),
4.16. ,
NOT !. ,
.
4.16.
<?php
$ = 1: $ = 0:
echo ($ AND $b)
echo ($ or $b)
"<br /> :
"<br />":
99
?>
NULL, 1, 1, NULL. ,
echo TRUE.
( , NULL, , FALSE.)
, AND, TRUE,
, ,
$ NOT, TRUE
(, ) FALSE. ,
, $ $ ,
1 0.
, , AND OR
, && 11.
----- , , && 11.
i f OR
, ,
TRUE. 4.17
getnext , Sfinished
1.
4.17. , 0R
<?php
i f (Sfinished == 1 OR getnext0 == 1) exit;
?>
, getnext if,
, 4.18.
4.18. i f
<?php
$gn = getnextO;
i f (Sfinished == 1 OR $gn == 1) exit;
?>
getnext
$gn i f.
, getnext
4 ,
^
.
. 4.5
. , !TRUE FALSE, 1FALSE
TRUE.
100
4.
4.5. ,
XOR
AND
OR
TRUE
TRUE
TRUE
TRUE
FALSE
TRUE
FALSE
FALSE
TRUE
TRUE
FALSE
TRUE
FALSE
TRUE
TRUE
FALSE
FALSE
FALSE
FALSE
FALSE
.
- .
-
,
- .
: i f , swi tch ?.
, , ,
, ,
( )
, .
if
. ,
,
.
i f , ,
, ,
TRUE.
,
. ,
TRUE,
(. 4.1).
i f , , , NULL
, ( ,
).
, TRUE, ,
, { }. ,
. ,
, , ,
, ,
, - -
101
. (, ,
, , ,
.)
. 4.1.
4.19 ,
, .
4.19. i f ,
<?php
i f ($bank_balance < 100)
{
Smoney
= 1000;
$bank_balance += Smoney;
}
?>
, $100 ( 100
). ,
$1000, . (
!)
$100 ,
( ).
, .
.
,
(,
). ,
,
.
102
4.
else
, TRUE,
,
- . else.
, . 4.2.
. 4.2. if else
i f . . .else TRUE,
.
FALSE, .
,
.
i f ... el se 4.20.
4.20. if ...e ls e ,
<?php
i f ($bank_balance < 100)
103
{
Smoney
= 1000;
$bank_balance += Smoney;
}
else
{
Ssavings
+= 50:
$bank_balance -= 50:
}
?>
, $100,
el se,
.
, i f , el se
, . (
. -, , , .)
elseif
,
. ,
el sei f . , el se,
, .
i f . . . e ls e if . . .else 4.21.
4.21. i f . . . e ls e if . . .else,
<?php
i f ($bank_balance < 100)
{
Smoney
= 1000:
$bank_balance += Smoney:
}
e ls e if ($bank_balance > 200)
{
Ssavings
+= 100:
$bank_balance -= 100:
}
else
{
Ssavings
+= 50:
$bank_balance -= 50;
}
?>
e ls e if i f
el se. , $200,
, ,
$100.
104
4.
(. 4.3).
elseif .
, , swi tch,
, , . .
switch
switch ,
, -
105
, , ,
. , : Home, About, News, Logi Li nks,
$page
, .
i f .. . e ls e if . . .else
, 4.22.
4.22. i f . . . e l s e i f
<?php
if
e ls e if
e ls e if
e ls e if
e ls e if
?>
(Spage
(Spage
(Spage
(Spage
(Spage
==
==
==
==
==
"Home")
"About")
"News")
"Login")
"Links")
echo
echo
echo
echo
echo
"
"
"
"
"
"
About
News"
Login
Links
, switch, 4.23.
4.23. switch
<?php
switch (Spage)
{
case "Home :
echo "
break;
case "About":
echo "
break;
case "News":
echo "
break;
case "Login":
echo "
break;
case "Links":
echo "
break;
Home":
About";
News";
Login":
Links":
}
?>
, Spage
switch. case.
, . ,
, , .
i
switch case .
break.
case switch .
106
4.
switch
, switch -
, break.
switch .
4.23 break
case, , TRUE,
, case. ,
$ News, , ,
case.
,
break , ,
case, . , break
.
switch
, ,
case. , , 4.23,
, 4.24.
4.24. default 4.23
break , default
,
d efau lt ,
break,
.
break.
switch ,
endswitch ( 4.25).
,
, , - .
4.25. switch
<?php
switch (Spage):
case "Home":
echo " Home";
break;
// . .
case "Links"
107
?
?
i f else. ,
, , .
3
pri nt echo, ,
pri nt, echo.
? , ,
: ,
TRUE, FALSE.
4.26 ,
.
4.26. ?
<?php
echo Sfuel <= 1 ? " " : " ";
?>
1 1 ( ,
Sfuel , ),
echo .
. ,
?, - ( 4.27).
4.27. ?
<?php
Senough = Sfuel <= 1 ? FALSE : TRUE;
?>
Senough TRUE
, 1 ,
FALSE.
? ,
i f , ,
, .
, ,
- .
, :
Ssaved = Ssaved >= Snew ? Ssaved : Snew;
1
1 () = 3,79 . . .
4.
108
, , :
Ssaved
=
Ssaved >= $new
?
$saved
$new;
//
//
//
//
//
//
$saved
$saved Snew
...
... $saved
...
... $new
,
.
Ssaved
$new. , ?, ,
, i f .
,
, ,
, , .
.
, - ,
.
.
, , . 4.4.
,
i f , , ,
.
109
while
4.26 ,
,
whi 1 ( 4.28).
4.28. while
<?php
Sfuel = 10;
while (Sfuel > 1)
{
// ...
echo " ";
}
?>
- ,
,
while. , ,
, ,
.
, if, while ,
.
4.29 whi 1,
12.
4.29. while 12
<?php
Scount = 1;
while (Scount <= 12)
{
echo " Scount. 12, " . Scount * 12 . "<b />";
++$count;
}
?>
Scount 1,
whi 1, Scount <= 12.
,
12. :
1,
2,
3.
. .
12. 12
12. 24
12. 36
110
4.
,
Scount, 12. ,
< />, .
, ,
Scount .
Scount , ,
12. , 2,
13.
, , whi 1,
, , .
++$count (
$count++) ,
.
1x12.
,
. 4.30.
4.30. 4.29
<?php
Scount = 0;
while (++$count <= 12)
echo " Scount. 12. " . Scount * 12 . "<br />":
?>
++Scount while
.
Scount () , ,
,
1 12. ,
Scount 0, 1,
, .
, 1, 2 12.
do...while
do... whi 1 whi 1,
, , ,
.
4.31 12,
.
4.31. do...w hile, 12
<?php
Scount = 1;
do
echo " Scount. 12. " . Scount * 12 . "<br />":
while (++$count <= 12);
?>
111
, $count
1 ( 0), ,
1.
4.29.
, do... whi 1 ,
, 4.32.
4.32. 4.31,
<?php
$count = 1;
do {
echo " Scount, 12. " . Scount * 12;
echo "<br />":
} while (++$count <= 12);
?>
for
for, ,
,
,
()
.
4.33
for.
4.33. / 12 for
<?php
for (Scount = 1 ; Scojrt <= 12 ; ++Scount)
echo " $coi>rt. 12, " . Scount * 12 . "<br />";
?>
, for,
. . for
:
;
;
.
: for ( 1 ;
2 ; ).
. Scount
1. (
Scount <= 12), ,
TRUE. ,
.
Scount 1.
4.
112
,
, .
for ,
( 4.34).
4.34. for 4.33
<?php
for (Scount = 1 : Scount <= 12 ; ++$count)
{
echo " Scount, 12, " . Scount * 12;
echo "<br />";
}
?>
, for, ,
whi 1. for
, .
,
, ,
. .
for
:
for (Si = 1. Sj = 1 ; Si + Sj < 10 ; Si++ . Sj++)
{
II
...
}
.
.
.
.
:
Si = 1. Sj = 1
Si + Sj < 10
$i++ , Sj++
// Si Sj
//
// Si Sj
, ,
, (
).
while
for?
. , whi 1
, , -
- , 1 ,
.
113
for ,
switch, break. ,
,
.
,
, , - ( 4.35).
4.35. , for
<?php
$fp = fopen("te x t.tx t".
'wb');
}
fclose(Sfp):
?>
,
.
, ,
text. txt , $f
,
.
100 ( 0 99),
data . fwrite
Swritten ,
. , fwrite
FALSE.
fwrite Swritten
FALSE, ,
, .
i f (Swritten = FALSE) break;
NOT:
i f ( ! Swritten) break:
, ,
:
i f ( !fwrite(Sfp. "data")) break;
break ,
, , ,
114
4.
, break , ,
, :
break 2;
continue
continue break,
,
.
, ,
.
4.36 conti nue ,
, $j 0.
4.36. continue
<?php
$j = 10;
,
.
. .
,
. 4.37,
,
.
,
4,66 6 .
115
4.37.
<?php
$ = 56;
$ = 12:
$ = $ / Sb:
echo $;
?>
, $
? ,
$/$
(int):
$ = (int) (Sa / Sb):
.
,
.
$, ,
$
.
,
. 4.6, ,
. ,
intval. ,
, ,
, .
4.6. ,
(int) (integer)
(bool) (boolean)
(float) (double) (real)
|
i
(string)
(array)
1
1
(object)
, - -,
. -
-,
, ,
cookie / , .
116
4.
, -,
,
,
.
-
. ,
-
, . .
,
-.
,
, , , ,
, . .
-, cookie (
),
- P H P -,
. ,
.
,
, WordPress (. 4.5).
,
P H P -,
, .
,
,
. , -
WordPress, ,
, ,
.
WordPress,
-, ,
P H P -,
.
,
.
P H P -.
, ,
, .
117
bookmarks
loots t t d p
x <s*
T|
http://myblog.com/blog/wp-admin/edit.php
P | ^
M yBlog |
Visit Sfafe)
Write
Posts
Manage
Pages
Comments
Links
Categories
Tags
Link Categories
Media Library
Manage Posts
All P o sts
| Delete |
Search Posts
Published (123)
Show dates
Scheduled (I)
8 .?<-
ho 7
C.itugories
Next
Status
Robin
Eco-friendly,
Organic, Retailing
Australia,
eko peko
(3
15 hours ago
Robin
Ethical, Fairtrade
Color,
Colour
2008/ /05
Robin
Eco-friendly,
Bamboo
__Organic______
9;
Scheduled
Published
Published
. 4.5. WordPress, ,
1. TRUE FALSE?
2. ?
3. , ?
4.
?
5. ?
6. (===)?
7. .
8.
?
9. for , whi 1?
10. _^ ' ,
?
,
4.
,
, ,
. ,
el se el sei f .
,
,
.
. ,
,
- .
, ,
,
.
.
.
.
.
,
, .
, ,
.
.
, ,
, .
, ,
.
,
( ).
119
,
.
, . , ,
print:
pri n t("print ");
, .
, ,
:
Notice: Use of undefined constant fname - assumed 'fn am e '
fname, , ,
, . (
, fname
.)
^
, print , 4 , . , :
ib:
, .
, phpi nfo,
:
phpinfoO;
. 5.1.
phpinfo ,
.
, .
5.1 ,
.
5.1.
<?php
echo strrevC' .dlrow o lle H "); //
echo str_repeat("Hip ". 2):
//
echo strtoupperC'hooray!"):
//
//
?>
5.
120
File
\
Edit
http://1ocalhost/info.php
View
Fgvorites
Tools
phpinfoQ
' 1r
ffi
fcielp
System
:.-
1:
L
*'-
11-
"
'
<U .
*
% -
. 5.1. , phpinfo
,
:
Hello world. Hip Hip HOORAY!
, strrev
, str_repeat Hip (
), strtoupper hooray!
.
:
function _{[ [, ... ]])
{
//
}
:
functi on;
,
, ,
;
121
;
,
( ,
).
,
print: PRINT,
P rin tn P rln T .
,
;
, .
return,
.
return - , ,
.
, -
,
.
5.1 P H P - strtoupper.
:
strtolower:
$lowered = strtolow er(" "):
echo $lowered;
, ,
, . (
, -Ann Jo-En-Lai.)
: u c first,
:
Sucfixed = u c fir s t ( " ");
echo Sucfixed;
:
,
s tr to l ower, u cfi rst.
strtolow er ucfi rst.
, ,
.
122
5.
print:
pri nt(5-8):
5-8 -3.
( ,
.) ,
:
pri nt(abs(5-8)):
.
1; 5-8, -3.
2. abs, -3 3.
3. , pri nt.
, ,
, .
:
ucfirst(strtolower( ", "))
strtol ower, ucfi rst,
( ,
):
,
( 5.2),
,
.
5.2. -
<?php
echo fix_names("WILLIAM", "henry", "gatES");
function fix_names($nl, $n2, $n3)
{
$nl = ucfirst(strtolower($nl)):
$n2 = ucfirst(strtolower($n2)):
$n3 = ucfirst(strtolower($n3));
return $nl . " " . $n2 . " " . $n3;
}
?>
Caps Lock,
, , ,
.
:
William Henry Gates
123
, .
.
. 3
, .
5.3.
5.3.
<?php
Snames = fix_names("WILLIAM", "henry", "gatES");
echo $names[0] . " " . $names[l] . " " . $names[2];
function fix_names($nl, $n2, $n3)
{
$nl = u c first(strto lo w e r($ n l));
$n2 = ucfirst(strtolow er($n2)):
$n3 = ucfirst(strtolower($n3));
return array($nl, $n2. $n3);
}
?>
, ,
-, ,
,
.
&, ,
, .
, ,
3.
, , ,
, ,
,
(. 5.2).
, , ,
.
, ,
. ,
.
, 5.3 : ,
(
5.4).
124
5.
. 5.2. ,
5.4.
<?php
$al = "WILLIAM":
$2 = "henry";
$ = "gatES";
echo Sal . " " . $a2 . " " . $a3 . "<br />";
fix_names($al, $a2, $a3);
echo Sal . " " . Sa2 . " " . Sa3;
function fix_names(&$nl, &Sn2, &Sn3)
{
Snl = ucfirst(strtolow er($nl));
Sn2 =.ucfirst(strtolower(Sn2));
Sn3 = ucfirst(strtolower(Sn3));
}
?>
,
. , , ,
&,
.
Snl, $2 $ ,
Sal, $2 $. , ,
, .
f i x_names
Snl, Sn2 $, Sal, $2 $.
:
WILLIAM henry gatES
William Henry Gates
125
, echo
Sal, Sa2 $.
.
, ,
.
, ,
. global
,
( 5.5).
<?php
Sal = "WILLIAM";
Sa2 = "henry";
Sa3 = "gatES";
5.5.
echo Sal . " " . Sa2 . " " . Sa3 . "<br />";
fix_names();
echo Sal . " " . Sa2 . " " . Sa3;
function fix_names()
{
global $al Sal = ucfirst(strtolower($al))
global $a2 Sa2 = ucfirst(strtolower($a2))
global $a3 Sa3 = ucfirst(strtolower($a3))
}
?>
,
.
, .
,
.
.
, 3.
,
. ,
, ,
. . , ,
126
5.
.
.
0 ,
,
.
, ,
, , ,
, . , ,
, .
.
. : i ncl ude () requi re
().
include
include
.
. 5.6 ,
1i brary.php.
5.6.
<?php
include "lib rary.p hp ";
//
?>
indude_once
include
, . , ,
1 ibrary. php . ,
, , , 1ibrary.
php. - 1i brary. php .
,
.
include_once
( 5.7).
127
5.7.
<?php
include_once "lib ra ry.p hp ";
//
?>
, i ncl ude i ncl ude_once,
, , .
, ,
, ,
i ncl ude.
---
----------------------------------------------------------------------------------------------
-, , include_once
4 * include. ,
-* .
require require_once
, include
include once, ,
. ,
.
, ,
require. ,
include_once, ,
, ,
requi re_once ( 5.8).
5.8.
<?php
require_once "lib rary.p hp ";
//
?>
.
- ,
function exists,
.
5.9 array_combine,
5.
128
5.
5.9.
<?php
i f ( f unction_exists( array_combine"))
{
echo " ";
}
else
{
echo " , ";
}
?>
,
, ,
, .
,
.
, ,
phpversion.
:
5.2.8
,
(
GOTO G0SUB), -
( )
.
,
, , .
, .
:
,
.
MySQL,
.
, ,
. User,
, ,
, . ,
,
User.
129
. , ,
, , , ,
.
,
.
, ,
, .
, , (
) .
, , ,
.
. . 5.3
. - ,
.
(, )
- (,
, , -).
. 5.3.
130
5.
. ,
.
.
:
.
, ,
, ,
. - ,
.
, , ,
, .
, .
, ,
. ,
( ).
.
,
,
() ().
, ,
,
.
,
cl ass.
( ), . 5.10
User, : Sname $password (
publ ic .
5 ).
( $object).
5.10.
<?php
Sobject = new User:
print_r($object):
class User
{
public $name, $password;
function save_user()
{
echo " . ":
131
}
}
?>
pri ntjr .
, ( readable,
). Sobject
:
User Object
(
[name] =>
[password] =>
)
,
:
User Object ( [name] => [password] => )
, Sobject
, , name
password.
new,
: % = new .
:
Sobject = new User;
Stemp = new User('name\
password'):
User.
.
; ,
.
5.10 .
5.11
.
5.11.
<?php
Sobject = new User;
print_r(Sobject): echo "<br />" :
$object->name = "Joe";
132
5.
$object->password = "mypass":
print_r($object): echo "<br />":
$object->save_user():
class User
{
public Sname, Spassword;
function save_user()
{
echo " , ":
}
}
?>
,
: %->. : %>{).
,
($). $,
, ,
. , $object->$property ,
Sproperty (,
brown), $object->brown. Sproperty
, $object->NULL,
.
,
, 5.11
:
User Object
(
[name]
[password]
)
User Object
(
[name]
[password]
)
=>
=>
=> Joe
=> mypass
.
pri nt_r,
$object .
print r,
,
, ,
.
133
, save user
, , ,
.
j
^
^
,
, .
-?* .
%
, .
,
, ,
, .
,
.
, 5.12,
User,
name.
?
<?php
$objectl
= new UserO;
$objectl->name = "Alice";
$object2
= $objectl;
$object2->name = "Amy";
echo "objectl name = " . $objectl->name . "<br />";
echo "object2 name = " . Sobject2->name;
5.12.
class User
{
public $name;
}
?>
Sobjectl name Alice.
$object2, $objectl
name $object2 , .
:
objectl name = Amy
object2 name = Amy
? Sobjectl, $object2 ,
name, $object2,
, Sobjectl.
clone,
. 5.13.
134
5.
5.13.
<?php
$objectl
= new UserO;
$objectl->name = "Alice";
$object2
= clone $objectl;
$object2->name = "Amy";
echo "objectl name = " . $objectl->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
. , :
objectl name = Alice
object2 name = Amy
. ,
.
,
5.14.
5.14. -
<?php
class User
{
function User($paraml, $param2)
{
//
public Susername = "Guest";
}
}
?>
5.15 , 5
,
__construct ( construct
).
5.15. - 5
<?php
class User
{
function _construct(Sparaml. $param2)
135
{
//
public Jusername = "Guest :
}
}
?>
5
5 -
. ,
. 5.16 ,
-.
5.16. 5 -
<?php
class User
{
function _ de stru ct()
{
//
}
}
?>
, ,
. , , (__),
.
, Sthis,
. ,
, 5.17,
User, get_password.
5.17. Sthis
<?php
class User
{
public Sname. Spassword:
function get_password()
{
return $this->password;
}
}
?>
get_password Sthis
, password,
5.
136
. ,
-> Spassword $.
, ,
.
, 5.17, :
Sobject
= new User
$object->password = "secret"
echo $object->get_password()
secret.
5
5 ,
, .
,
5.18.
5.18.
<?php
User::pwd_string();
class User
{
static function pwd_string()
{
echo ", ":
}
}
?>
,
->
(::), .
, ,
.
5.21 .
$this->property
.
,
.
User 5.19 ,
, .
137
5.19.
<?php
Sobjectl
= new UserO;
$objectl->name = "Alice";
echo $objectl->name;
class User {}
?>
1 i ,
$objectl->name.
,
, name .
, ,
,
. , .
, ,
. ,
.
5.20.
5.20.
<?php
class Test
{
public
public
public
public
Sname
Sage
Stime
Sscore
= "Paul Smith";
=42;
= timeO;
= Sieve! * 2 ;
//
//
// -
// -
}
?>
.
, ( 5.21).
5.21.
<?php
Translate;:lookup();
class Translate
{
const
const
const
const
II
ENGLISH
SPANISH
FRENCH
GERMAN
=
=
=
=
0
1
2
3
...
function lookupO
5.
138
{
echo self::SPANISH:
}
}
?>
, s e lf
. , ,
,
, . , ,
, 1.
, .
5
5
.
publ i ().
var public
.
var public .
var ,
. .
protected ().
.
private ().
,
.
, ,
.
(public) ,
.
(protected) ,
,
.
(private) ,
.
5.22.
5.22.
<?php
class Example
139
{
var Sname
= "Michael": 11 He , public
public Sage = 23;
//
protected Susercount:
//
private function adminO //
{
// admin
}
}
?>
. ,
User ,
.
.
,
. , ,
, ,
User.
.
5.18, , ,
. , ,
,
.
5.23 Test,
.
5.23.
<?php
Stemp
echo
echo
echo
= new TestO;
"Test
A:
"Test
B:
"Test
C:
"
"
"
T e st;:$static_property "<br
/>":
.
Stemp->get_sp()"<br
/>":
.
$temp->static_property"<br
class Test
{
s ta tic $static_property = " ":
function get_sp()
{
}
}
?>
return s e lf::$static_property:
/>";
140
5.
,
:
Test :
Test :
Notice: Undefined property: Test: :$static_property
Test C:
, Sstatic property
, Test .
Test get_sp Stemp,
Test. Test ,
Sstatic_property Stemp.
, get sp
Sstatic property, self.
.
, .
:
, , ,
,
. extends.
5.24 Subscriber User
extends.
5.24.
<?php
Sobject
= new Subscriber;
Sobject->name
= "Fred";
$object->password = "pword";
$object->phone
= "012 345 6789";
Sobject->email
= "fred@bloggs.com";
$object->display();
class User
{
public Sname, Spassword;
function save_user()
{
echo " . ";
}
}
class Subscriber extends User
141
displayO
"Name:
"Pass:
"Phone:
"Email:
"
"
"
"
. $this->name
"<br />";
. $this->password . "<br />":
. $this->phone
"<br />";
. $this->emai1:
}
?>
User Sname Spassword,
.
Subscriber Sphone
Semai 1 , ,
$thi s.
, .
:
Name:
Pass:
Phone:
Emai1:
Fred
pword
012 345 6789
fred@bloggs.com
parent
,
,
.
.
parent, 5.25.
5.25.
parent
<?php
Sobject = new Son;
$object->test():
$object->test2():
class Dad
{
function testO
{
echo "[Class Dad] < />";
}
}
class Son extends Dad
{
function testO
142
{
5.
}
function test2()
parent::test();
}
}
?>
Dad (), Son (),
,
test. , test,
. test
, Dad,
parent, test2 Son.
:
[Class Son]
[Class Dad]
,
self:
s e l f : :method ;
, -
. , ,
5.26, .
5.26.
<?php
Sobject = new T ig e r O ;
echo " .. .<br>";
echo ": " . $object->fur . "<br />";
echo ": " . $object->stripes:
class Wildcat
{
public $fur; //
fu n c tio n _constructO
{
}
}
$this->fur = "TRUE":
143
public Sstripes; 11
function__constructO
{
parent::__construct( ); 11
11
$this->stripes = "TRUE":
}
}
?>
.
Wi ldcat ( ) Sfur (),
, Tiger (),
$fur, $stripes ().
, :
...
: TRUE
: TRUE
Final
final. , 5.27.
5.27. final
<?php
class User
{
final function copyrightO
{
echo "
}
}
?>
,
, .
- .
6
.
1. , ?
2. ?
3. ?
144
5.
4. ?
5. ?
6. ?
7. ?
8.
?
9. ?
0. ?
,
5.
3 ,
.
,
, ,
.
,
,
.
. ,
, , .
,
( )
.
,
- .
,
, .
.
, -
,
. ,
,
.
6.1.
146
6.
6.1.
<?php
$[]
$paper[]
$paper[]
$paper[]
=
=
=
=
"Copier";
"Inkjet";
"Laser";
"Photo";
print_r($paper);
?>
$
,
,
, .
pri nt_r ( ,
) .
:
Array
(
[0]
[1]
[2]
[3]
=>
=>
=>
=>
Copier
Inkjet
Laser
Photo
)
, 6.2,
. , ,
,
. ,
- ,
.
6.2.
<?php
$[0]
$paper[l]
$paper[2]
$paper[3]
=
=
=
=
"Copier";
"Inkjet";
"Laser";
"Photo";
print_r($paper);
?>
, ,
- print r,
6.3 ,
, -.
6.3.
<?php
$paper[] = "Copier";
147
$paper[] = "Inkjet";
$[] = "Laser";
$paper[] = "Photo";
for ($j = 0 ; $j < 4 ; ++$j)
echo "$ j; $paper[$j]<br>";
?>
:
0:
1:
2:
3:
Copier
Inkjet
Laser
Photo
,
, ,
. .
, ,
, . ,
.
.
, .
6.4 ,
.
6.4.
<?php
$paper['copier']
$paper['inkjet']
$paper[laser]
$paper['photo']
=
=
=
=
echo $paper['laser']:
?>
(
, ) ,
- ,
echo, Laser Pri nter. (copi er, i nkjet . .)
, , (, Laser
Printer) .
X M L HTML. , H TM L-,
, - ,
:
148
6.
,
array
,
.
, , : ,
.
array. 6.5
, ,
.
6.5. array
<?php
$pl = ray("Copier", "Inkjet". "Laser". "Photo");
echo " pi: " . $pl[2] . "<br>";
$p2 = array('copier'
'inkjet'
'laser'
'photo'
=>
=>
=>
=>
foreach...as
149
, $1 $2 , ,
,
(undefined index) (undefined
offset),
:
echo $ p l[ 'in k je t ]; //
echo $2['3 ']:
//
foreach...as
.
,
, ,
foreach. . .as. ,
- .
,
, . 6.6
, foreach
6.3.
6.6. ,
foreach.. .as
<?php
Spaper = array("Copier". "Inkjet", "Laser", "Photo");
$j = 0:
foreach ($paper as Si tern)
}
?>
PHP foreach,
, as,
foreach
.
$i tern , Spaper.
, .
, 6.3.
, foreach .
6.7 6.5.
6.7. ,
foreach...as
<?php
Spaper = array('copier' => "Copier & Multipurpose".
150
6.
<?php
Spaper = array( 'copier'
'inkjet'
'laser'
'photo'
=>
=>
=>
=>
<?php
list(Sa, Sb) = array('Alice'. 'Bob');
echo "a=$a b=$b";
?>
151
:
a=Alice b=Bob
, .
foreach.. .as ,
, as,
each .
.
(
).
, , ,
, , , ,
.
, ,
( 6.10).
6.10.
<?php
Sproducts = array(
'paper' =>
array(
'copier' => "Copier & Multipurpose".
'in k je t' => "Inkjet Printer".
'lase r' => "Laser Printer".
photo' => "Photographic Paper").
'pens' => array(
'b a ll'
=> "Ball Point".
' hi 1i t e => "Highlighters".
'marker' => "Markers").
'misc' => array(
'tape'
=> "Sticky Tape".
'glue'
=> "Adhesives".
'c lip s ' => "Paperclips") );
echo "<pre>";
foreach ($products as $section => Si terns)
foreach (Siterns as Skey => Svalue)
echo "$section:\t$key\t(Svalue)<br>";
echo "</pre>";
?>
152
6.
,
. , Spaper
,
Sproducts. : paper, pens
mi sc, ,
.
.
, bal 1
, -.
.
foreach.. .as.
,
.
, (
),
.
echo \t,
.
-, , ,
, <>.. .</>,
-
. , ,
:
paper:
paper:
paper:
paper:
pens:
pens:
pens:
mi sc:
misc:
mi sc:
copier
inkjet
laser
photo
ball
h ilite
marker
tape
glue
clips
,
:
echo Sproducts['misc ]['glue']:
Adhesi ves.
,
, -
. 6.11
.
<?php
Schessboard = array(
array( ' r ', ' n ', b\ 'k\ 'q'.
array('p '. V - ;p;. 'P '. ;p;.
array( '.
arrayC '.
array(' ',
arrayC ' .
array( ' P' . 'P ' . p\ *P', p1.
array('R . N*, 'B\ 'K ' . Q".
6.11.
153
'p*. p\ 'P').
' *. 'N', R'))
echo "<pre>";
foreach (Schessboard as Srow)
{
foreach (Srow as Spiece)
echo "Spiece ";
echo <br />";
}
echo n</pre>";
?>
,
. : rook (
), n knight (), b bishop (), k kin g (), q queen ()
paw n ().
foreach.. .as.
Srow,
,
Schessboard .
, .
,
(Spi ), (
). ,
. <> </>
:
rnbkqbnr
RNBKQBNR
,
:
echo $chessboard[7][4];
154
6.
Q ,
(
, , ).
1i st each ,
, .
http://tinyurl.com/phparrayfuncs.
, .
is_array
. ,
$f red ,
$f red. ,
, is_array:
echo (is_array($fred)) ? " " : " ";
, $f red ,
Undefined variable.
count
each foreach... as
, ,
, .
:
echo count($fred);
,
, :
echo count($fred. 1);
. ,
,
, .
sort
,
.
:
155
sort($fred):
,
,
. TRUE
FALSE .
. ,
, , :
sort($fred. SORT_NUMERIC);
sort($fred. SORT_STRING);
,
rsort:
rsort($fred, SORT_NUMERIC);
rsort($fred. SORT_STRING);
shuffle
, , ,
:
shuffle(Scards);
sort, shuff1
TRUE
FALSE .
explode
, ,
, ( ),
. 6.12
,
, , .
6.12.
<?php
Stemp = explodeC '. " ");
print_r($temp);
?>
(
):
Array
(
[0] =>
[1] =>
[2] =>
156
6.
[3] =>
[4] =>
)
, ,
. 6.13
.
6.13. , ***,
<?php
Stemp = explode('***'. "*********");
print_r($temp);
?>
6.13 :
Array
(
[0]
[1]
[2]
[3]
=>
=>
=>
=>
extract
. $_GET S P0ST,
, -
, .
GET, $_GET,
POST $_P0ST.
, ,
.
.
:
extract ($_GET);
, , q
Hi there,
$q, .
, -
,
. ,
,
:
extract($_GET. EXTR_PREFIX_ALL. Mtomget');
157
, ,
$q $f romget q.
$_GET $_P0ST ,
, 1
, ,
-.
compact
compact,
extract, .
6.14.
6.14. compact
<?php
$fname
Ssname
Saddress
Scity
Scountry
=
=
=
=
=
"Elizabeth";
"Windsor";
"Buckingham Palace";
"London";
"United Kingdom";
6.
158
= 61;
reset
foreach.. .as each
,
, ,
. ,
reset,
, .
:
reset(Sfred);
//
Sitem = reset(Sfred): //
// Sitem
end
, end, ,
,
:
end($fred);
Sitem = end(Sfred);
. ,
, .
.
159
1. ?
2. array?
3. foreach each?
4. ?
5. ?
6. expl ode?
7.
?
,
6.
.
, .
,
,
, -
.
, ,
.
XHTML,
, HTML, (
XML, , RSS).
,
-.
printf
print echo,
.
pri ntf,
. pri ntf ,
,
. ,
%6, 3
:
p rin tf(" % ". 3):
% %, 3 (11).
. 7.1
.
161
printf
7.1. , printf
,
arg
( arg,
123)
% (
)
arg
1111011
ASCII- ,
arg
arg
123
arg
1.23000+2
arg
123.000000
arg
173
arg
123
arg
123
arg
arg
7
pri ntf ,
%.
: . 33 , 21
:
p r in t f(" %s. 2d , % ",
'Simon', 33, 33):
- ,
, , ,),
.
printf HTML, .
, , , :
65 , 127 245 ,
.
:
printf("<font color='#TOX%X >npHBeT</font>". 65. 127. 245):
,
( ' (#),
. %,
. :
162
7.
<font color='#417FF5'></font>
printf
. ,
$r, $ $,
:
printf("<font color='#^X%X^X,>npnBeT</font>". $r-20. $-20. $b-20);
,
. , , ,
.
(, $123,42 12, $10,285).
,
, %
. 2:
^-: $*.2f". 123.42 / 12);
:
: $10.29
,
,
, . 7.1
.
7.1.
<?php
echo "<pre>"; // .
// 15 -
p r in t f( " $%15f\n". 123.42 / 12):
// 15 -
p r in t f(" $ 5 " . 123.42 / 12);
// 15 -
//
pri n t f( " $*15.2f\n". 123.42 / 12);
// 15 -
//
pri n t f( " $015.2f\n". 123.42 / 12);
// # 15 -
pri n tf ( " $r# 15.2f\n". 123.42 / 12);
?>
printf
163
$
10.285000
$00000010.285000
$
10.29
$000000000010.29
$########10.29
,
(. 7.2). .
f, .
, , .
,
, -,
. 15.
-
, .
% 0,
, -.
, .
, - ,
- , ,
: '#.
%,
.
7.2.
%
%
%
15
0
10.285000
15
.4
000000000010.29
15
.2
########10.2850
, ,
. 7.2.
7.2.
<?php
echo "<>": // .
164
7.
$h = House';
p r in t f(
p r in t f(
p rin tf(
prin tf(
p rin tf(
[*s]\n\
[*10s]\n\
C%-10s]\n".
[*010s]\n".
[*'#10s]\n\n"
Sh)
Sh)
Sh)
Sh)
Sh)
/
/
/
/
/
/
'#
Sd = 'Doctor House';
printf("[10.8s]\n",
Sd); //
//
Sd); //
printf("[X -10.6s]\n",
//
p rin tf( " [ - @10.6s]\n". Sd); //
//
8
6
,
?>
, -
H T M L- <>,
\. :
[House]
[
House]
[House
]
[OOOOOHouse]
[#####House]
[ Doctor H]
[Doctor
]
[Doctor@@@@]
-
, ,
, ,
-.
. 7.3 ,
.
7.3.
[House]
10
[House ]
[####Hous]
%
%
%
'#
.4
165
sprintf
,
. spri ntf.
, -
.
spri ntf ,
RGB 65,127,245,
Shexstri ng:
Shexstring = sprintfC'&XTOX", 65, 127, 245);
,
:
$out = sprintf(":
echo $out;
123.42 / 12);
Unix, ,
1 1970 .
time:
echo timeO;
,
,
7 24 60 60
:
echo timeO + 7 * 24 * 60 * 60;
,
mkti me. 946684800
2000 :
echo mktime(0, 0. 0. 1, 1. 2000);
( ):
(0-23);
(0-59);
(0-59);
(1-12);
(1-31);
(1970-2038 1901-2038 5.1.0 + 32-
).
7.
166
, 1970- 2038-? ,
Unix 1970 ,
. , ,
, 5.1.0, , 32-
, 1901 2038 .
, Unix ,
70 , ,
32- ,
19 2038 . ,
Y2K38 ( 2000 , ,
, ).
, .
date,
,
. :
date($format. Stimestamp):
Sformat ,
, . 7.4, $timestamp
Unix.
http://tinyurl.com/phpdatefuncs.
Thursday April 15th, 2010 - 1:38pm:
echo dateC'l F jS. Y - g:ia", timeO):
7.4. , date
01- 31
Sun
j
1
1 31
Sunday Saturday
, ,
1 7
(
j)
st, nd, rd th
, ,
0 6
0 365
01 52
January December
01 12
Jan Dec
1 12
28, 29, 30 31
167
0000 9999
00 99
1 - , 0 -
am pm
AM
, 12-
1 12
, 24-
1 24
, 12-
01 12
, 24-
01 24
00 59
00 59
,
, ,
,
. , date(DATE RSS) ,
RSS-.
.
DATE AT0M Atom. P H P - Y-m-d\TH:i:sP,
2012-08-1612:00:00+0000.
DATE COOKI cookie, - JavaScript.
P H P - 1, d-M-y H:i:s , Thu,
16-Aug-2012 12:00:00 UTC.
DATE RSS RSS. P H P - D, d Y H:i:s ,
Thu, 16 Aug 2012 12:00:00 UTC.
DATE_W3C , World Wide Web
Consortium. P H P - Y-m-d\TH:i:sP,
- 2012-08-1612:00:00+0000.
http://tinyurl.com/phpdates.
checkdate
, ,
, ?
, checkdate, TRUE,
, FALSE .
7.
168
, 30 ,
. 7.3 ,
. .
7.3.
<?php
$month = 9;
$day =31;
$ = 2012;
//
// 31-
// 2012
( 30 )
MySQL (
) -.
, .
,
, , .
. ,
, ,
, . ,
Windows Mac OS X , Linux
Unix . ,
,
.
,
file exists, TRUE, FALSE
:
i f (fi 1e exists("te s tfile .tx t")) echo " ";
testfi 1 .txt ,
. , 7.4,
testfi 1 . php.
7.4.
<?php // te s tfi1 .php
$fh = f open ("te s tfile .tx t". V ) or die("Co3flaTb ");
$text = < END
169
1
2
3
JND;
fwrite($fh. $text) or d i(" ");
fclo se($ fh );
echo " 'te s tfile .tx t' ";
?>
,
: 'testfile.txt' .
, ,
, ,
.
.
, testfi 1 .txt ,
testfi 1 . php.
, :
1
2
3
.
1. fopen.
2. .
(fwrite),
(fread fgets) .
3. (fcl ose).
, ,
.
, -
. $fh
( ) ,
fopen. ,
, fwrite fcl ose,
$fh, .
Sfh , ,
.
.
fopen FALSE.
:
di ,
.
, -
( - ).
7.
170
, fopen.
w, .
, . :
, w fopen
( !).
. 7.5 ,
.
7.5. , fopen
;
. FALSE,
'+'
;
. FALSE,
;
. ,
'w+'
;
. ,
''
;
. ,
'+'
;
.
,
, ,
, 7.5, fgets ( s
string ).
7.5. fgets
<?php
$fh = fo p e n C te s t file .t x t" . ' ') or
, "):
Sline = fg ets($fh):
fclo se ($ fh ):
echo Sline:
?>
, 7.4,
:
1
171
,
f read, 7.6.
7.6. fread
<?php
$fh = fopen( "te s tfile .tx t". ' r ') or
die("a , "):
Stext = fread(Sfh. 3):
fclose(S fh):
echo Stext;
?>
fread ,
:
fread .
,
.
testfi le .txt, -uneii . 7.7 copyf i 1 . php,
.
7.7.
?>
,
testfi 12.txt. , ,
,
, 7.8.
7.8.
<?php // copyfi12.php
i f ( !copy( ' t e s t f i l e . t x t 't e s t file 2 .t x t ') ) echo " ";
else echo " t e s t f i 12.t x t ;
?>
, 7.9.
7.9.
<?php // movefile.php
i f ( !rename(t e s t file 2 .t x t '.
7.
172
?>
.
,
f i l e exists.
, 7.10,
uni i nk, .
7.10.
<?php // d e le te fi1e .php
i f ( !u n lin k(t e s t f i 1e2.new )) echo " ";
else echo " 'testfile2.new ' ";
?>
,
. ,
,
.
, ,
, ,
, f i 1e_exi sts
uni i nk.
, .
(. . 7.5) ,
,
, .
,
.
( 7.4 Sfh),
, .
, 7.11, update. php,
, .
7.11.
<?php // update.php
$fh = fopen("testfile.txt", ' r+') or die("Co ");
Stext = fgets($fh);
173
fseek($fh, 0. SEEKJND):
fwrite($fh, "$text") or ' ");
fclose($fh);
echo " 'te s tfile .tx t ";
?>
testfi 1. txt ,
' +',
. fgets,
( ).
f seek, ,
, ( Stext),
. :
1
2
3
1
, .
fseek, $fh,
, 0 SEEK_END. SEEK END
, 0 ,
. 7.11 0,
.
fseek :
SEEK_SET SEEK_CUR. SEEK_SET
, .
18:
fseek($fh, 18. SEEK_SET);
SEEK_CUR ,
.
18,
23:
fseek($fh, 5, SEEK_CUR);
,
( )
.
fseek
, .
. .
-
.
174
7.
, .
, ,
, .
, f 1ock.
,
. ,
,
,
, 7.12, 7.11.
7.12.
<?php
Sfh = fopen(te s tfile .tx t" . ' r+') or die(" "):
Stext = fgets(Sfh):
i f (flock(Sfh, LOCKJX))
{
fseek(Sfh, 0. SEEKJND);
fwrite (Sfh. "Stext") or ' "):
flock(Sfh, LOCKJJN);
}
fclose(Sfh):
echo " 'te s tfile .tx t' ":
?>
-
:
.
. 7.12 f 1ock
fwr i te.
f 1ock L0CK_EX
, Sfh:
flock (Sfh, LOCKJX):
, ,
LOCKJJN:
flock(Sfh, LOCKJJN):
,
. ,
:
.
, ,
i f? , f 1ock -
175
,
, , .
, flock
. ,
, . ,
, flock,
.
- ,
, ,
.
flock NFS
, . flock
ISAPI,
PHP-,
. , flock ,
FAT, Windows.
f i le_get_contents.
, 7.13.
7.13. file_get_contents
<?php
echo <pre>";
// .
?>
.
. 7.14
HTM L - O Reilly ,
-.
, . 7.1.
7.14. - O 'R e illy
<?php
echo f i 1e_get_contents("http ://o re i1l y .com" );
?>
-
- ,
, ,
.
, multipart/form-data,
176
7.
-. , ,
7.15, upload.php.
, ,
.
I
\Q
| httpy'/lolhost/amp!e7-14.php
; : file
yiew
drt
dit
Favorites
lo ok
- f t&
fcjelp
O REILLY
Your Account
.TSj Shopping Cart
Home
Shop
Answers
Conferences
Training
School of Technology
&
Popular Topics: Programming JavaScript IPhone Android Python HTML5 & CSS Microsoft Java Perl Linux Data
Community
Si
Search
; Search
All order s over $29.' qualify for FREE SHIPPING within the US
Programming
Entity FrameworV
DbContext
Ebook -S7.49
(Save 50%)
7.15. , upload.php
<?php // upload.php
echo <_END
<html><head><title>PHP-$opMa cepBep</title></head><body>
<form method^post action= upload.php enctype='multi part/form-data'>
: <input ty p e = 'file ' name='filename' size= 10' />
<input type='submit' value='' />
</form>
_END:
i f ($_FILES)
{
Sname = $_FILES[,filen am e'][,name']:
move_uploaded_fi1e($_FILES[' f i 1ename ] [ 'tmp_name']. $name):
echo " '$name'<br /xim g src='$name' /> :
}
echo "</body></html>";
?>
177
.
echo H T M L-, ,
.
, POST,
upload.php (
) - ,
multipart/
form-data.
, .
.
i nput type, f i 1,
name, f i 1ename,
size, ,
.
,
( ,
, Submit Query, ).
.
-, :
,
.
P H P -, ,
,
$_FILES.
, S FILES . i f
($_FILES).
,
, $_FI LES , .
,
$_FI LES.
, , ,
, ,
$name. ,
, .
move_upl oaded_f11, ,
.
,
<IMG>. . 7.2.
move_uploaded_file
Permission denied, ,
, .
178
7.
/) - Mo^ilUi I irefux
x ii
; Q
http7//lQcalhost:/web/upload.php
&
j i^
.. 11
'smiley jpg1
. 7.2.
$_FILES
$_FILES ,
. 7.6 ( ,
).
7.6. $_FILES
$_FILES['file]['name']
(, smiley.jpg)
$_FILES[,file'][type']
(, image/jpeg)
$_FILES[,file'] ['size']
$_FILES[,file,][,tmp_name']
$_FILES['filel]['error']
M IM E - (Multipurpose Internet
Mail Extension ).
, ,
(Internet media types). . 7.7
,
$_FILES[ ' f i 1' ] [ 'type '].
7.7. ,
application/pdf
image/gif
multi part/form-data
text/xml
application/zip
image/jpeg
text/css
video/mpeg
audio/mpeg
image/png
text/html
video/mp4
audio/x-wav
image/tiff
text/plain
video/quicktime
179
, ( )
,
.
, ,
, ,
.
upl oad.php upl oad2.
php, 7.16.
7.16. upload.php
<?php // upload2.php
echo <_END
<html><head><title>PHP-(j)opMa cepeep</title></head><body>
<form method='post' action='upload2.php' enctype='multipart/form-data>
JPG. GIF. PNG TIF:
{
Sname = S_FILES['filename']['name'];
swi tch($_FILES[f i 1ename'] [ 'type'])
{
case 'image/jpeg'; $ext = ' jp g ';
case 'image/gif': $ext = 'g i f ';
case 'image/png : $ext = 'png';
case 'im a g e/tiff': $ext = 'ti f ';
default;
$ext = '';
}
break;
break;
break;
break;
break;
i f ($ext)
{
$n = "image.$ext":
move_uploaded_fi1e($_FILES[' f i 1ename'] [ 'tmp_name'], $n):
echo " 'Sname' '$n':<br />";
echo "<img src='Sn />";
}
else echo "'$name' - ";
}
else echo " ";
echo "</body></html>";
?>
, H T M L-, ,
7.15 20 , i f ($_FILES).
, i f
,
180
7.
el se, ,
.
i f Sname ,
( ) ,
, .
swi tch,
,
. $ext
, .
, ,
Sext "".
, $ext ,
$ ,
image , $ext. ,
: image, jpg, image.gif, image.png image.tif.
, P H P -
.
, ,
.
, , , , , , .
i f else,
,
, .
,
.
-
, . ,
,
, ,
, .
,
, - ,
,
(. 17)
Sname:
Sname = ereg_replace("[*A-Za-zO-9.]"f "". Sname):
Sname A-Z, a-z,
0-9 , .
181
,
, ,
:
Sname = strtolower(ereg_replace("[^A-Za-zO-9.]".
Sname));
image/pjpeg,
JPEG-.
image/jpeg:
case 'image/pjpeg':
case 'image/jpeg': $ext = 'jpg'; break;
,
, .
.
,
, 7.17.
Windows Windows- dir.
Linux, Unix Mac OS X
,
1s. ,
exec. php .
7.17.
<?php // exec.php
Scmd = "dir";
// Windows
// Scmd = "Is"; // Linux, Unix & Mac
exec(escapeshellcmd($cmd), Soutput, Sstatus);
i f (Sstatus) echo " exec ";
else
{
echo "<pre>";
foreach(Soutput as Sline) echo "$line\n";
}
?>
( Windows di ):
Volume in drive is HP
Volume Serial Number is E67F-EE11
Directory of C:\web
182
7.
20/01/2011
10:34
20/01/2011
10: 34
19/01/2011
20/01/2011
20/01/2011
19/01/2011
19/01/2011
20/01/2011
16::26
236 maketest.php
10::47
198 exec.php
13.741 smiley.jpg
08::04
54 test.php
18::01
16::59
35 te s tfile .tx t
886 upload.php
09::35
6 File(s)
15.150 bytes
2 Dir(s) 382.907.748.352 bytes free
exec .
1. ( $cmd).
2. , ,
( $output).
3. (
Sstatus).
Soutput Sstatus ,
, ,
, .
escapeshel 1cmd.
, ,
,
.
, -
.
. , ,
, Windows, Linux/Unix,
.
XHTML
X H T M L (extensible Hypertext Markup Language
) ,
. , H TM L- <br>
X H T M L - <br />
?
, , X H T M L
HTML, ,
. HTM L
(), XHTM L,
XHTML
183
XHTML
X H T M L ,
X M L -. ,
- (
iPhone Blackberry, ,
Android Windows, ),
, ,
, - ,
. , XHTML,
, -
.
, ,
,
- XHTML. ,
HTM L XHTML,
.
XHTML
X H T M L
, ,
, X H T M L 1.0.
X H T M L (, 1.1, 1.2 2.0),
,
-,
, .
XHTML HTML
X H T M L HTM L .
.
, ,
/ >. , , <input type=' subm it>
, Ter<input type=' submit' />. ,
<> </>,
< />.
. <> <i >
</ ></ i > , <>
<i>. <> <i ></i ></b>.
184
7.
.
, <form method=post action=post .php>, <form
method=' post' acti on=' post. php' >. :
<formmethod="post" action="post.php">.
(&) . ,
Batpian & Robin Batman & Robin.
, URL- : H T M L- <
tiref="index.php? page=12&item=15"> < href="index.php?
v page=12&item=15">.
X H T M L ,
. H T M L-, <B0DY><DIV ID="heading">,
: <body><di v id="heading">.
, ,
<option name="bill" selected>,
: <option name="bil1" selected="selected">. ,
checked disabled, checked="checked",
disabled="disabled" . .
X H T M L
X M L -. : <?xml
version=" 1.0" encoding="UTF-8"?>.
DOCTYPE.
<html > xml ns.
, 7.18,
X H T M L 1.0.
7.18. XML
XHTML
185
HTML 4.01
,
, D0CTYPE,
. , H TM L 4.01
(Document Type Declarations (DTD)). DTD
7.19 HTM L 4.01.
7.19. DTD HTML 4.01
HTML5
HTML5 ,
:
<!DOCTYPE html>
html , ,
- HTML5. ,
2011
HTML5, ,
, ,
.
XHTML 1.0
, HTML-
. X H T M L 1.0 ,
.
DTD 7.22
.
7.
186
XHTML
XHTM L, W 3C
http://validator.w3.org,
U R L -
-. ,
, , ,
. ,
X H T M L -, . 4
XHTML, ,
, . . 7.3 ,
7.18 X H T M L 1.0.
3 http://validator.w3.org/check7unrhttp%3A%2F1
*
file
dit
iew
Favorites
loots
La
fcjdp
jhtfcp://validator.w3.org/
Encoding : i utf-8
Doctype : j XHTML 1.0 Strict
Root Element
Root Namespace:
I(detect automaticatly)
|(detect automatically)
html
http://www.w3.orq/1999/xhtml
The W3C validators are hosted on server technology donated by HP, and
supported by community donations.
Donate and help us build better tools for a better web.
'
187
. ,
, X H T M L . .
1. pri ntf
?
2. pri ntf Happy
Bi rthday **?
3.
pri ntf , ?
4. Unix ,
7:11 May 2nd, 2016?
5. fopen,
?
6. P H P - fi 1 . txt?
7. P H P -
?
8.
?
9. P H P - ?
10. X H T M L 1.0: <input type=file
name=file size=10>?
,
7.
MySQL
10 M ySQL ,
,
-. 1990-
, ,
-.
, , ,
. ,
, ,
.
M ySQ L ,
-.
, eW EEK, ,
MySQL Oracle
.
MySQL
,
,
.
MySQL SQL Structured Query Language
. ,
,
, Oracle Microsoft SQL Server.
:
SELECT t i t l e FROM publications WHERE author = 'Charles Dickens':
MySQL ,
, . , ,
. . 8.1 ,
, ,
, .
MySQL
189
8.1.
Author ()
Title ()
Type ()
Year()
Mark Twain
( )
Fiction
()
1876
Jane Austen
( )
Fiction
()
1811
Charles Darwin
( )
Non-Fiction
()
1856
Charles Dickens
( )
Fiction
()
1841
William Shakespeare
( )
Play
()
1594
MySQL,
MySQL.
,
publications ().
, ,
, , classics.
,
, ,
:
MySQL;
,
;
, ;
.
, ,
,
, ,
.
MySQL
M ySQ L :
, - phpMyAdmin
, .
10, .
8. MySQL
190
Windows, Mac OS X Linux.
Windows
, 2,
Zend Server WAMP, M vSQL
( 32-, 64- ):
:\Program F i 1es\Zend\MySQL51\bin
C:\Program F ile s (x86)\Zend\MySQL51\bin
fit
**--1
4 , .
M ySQ L root ,
. , ,
,
.
MySQL,
CMD,
Enter. Windows.
, (
):
"C:\Program Files\Zend\MySQL51\bin\mysql" -u root
"C:\Program F ile s (x86)\Zend\MySQL51\bin\mysql" - root
tit
1 --------------------------------------------- :---------------
#%
, .
, ---- , ,
Command.
MySQL root
. M ySQL
. , ,
,
. 8.1:
SHOW databases;
, , M ySQL
Zend Server ( 2). ,
.
MySQL
191
Hi & '
| C:\Windows\system32\cmd.exe
M ic r o s o f t H in d us f U e r s i o i f . i. 1
Copjst4
\ > Mi Co i-po svvf:io n .
f i l l r:i<< >t: n r e s e r v e d .
f be i n : '* v * \h '
f o r h e lp .
:
1 c ts v;
!
!
j.n s e t
\o J tn
c le a r
:ht: b u F F e r.
<;0 >
nysfj]./ ^
Mac OS X
, ,
, 2, Zend
Server . -
MySQL.
M ySQL
Terminal ( Utilities Finder).
MySQL, /usr/local/zend/
mysql/bin.
M ySQL
root, root.
:
/usr/loca-1/zend/mysql/bin/mysql -u root
M ySQL root
. , ,
( . 8.2):
SHOW databases;
,
MySQL (Can't connect to local MySQL server through socket), ,
MySQL. ,
2, MySQL OS X.
.
Linux
, U nix-
, Linux, M vSQ L
192
8. MySQL
,
. M ySQL,
:
mysql -u root -
| information_schema |
I nysql
j
I test
|
3 rows in set (0.00 sec)
mysql> |
M ySQL root
. , ,
Enter.
,
,
. 8.3:
SHOW databases:
- ,
2 LAM P Linux,
MySQL.
,
.
MySQL
M ySQL
Telnet (
SSH), , ,
Linux/FreeBSD/Unix.
, ,
, .
MySQL
193
MySQL ,
. , ,
username :
mysql -u username -
.
,
. 8.3:
SHOW databases;
pi ,
test .
,
,
. , ,
,
, .
, .
. .
, , ,
Windows, Mac OS X Linux
194
8. MySQL
MySQL, ( ,
) .
. , , ,
(;) SHOWdatabases;? MySQL
. , MySQL
.
, ,
. ,
. Enter
.
at -
4
MySQL.
, , .
, Enter, .
MySQL (. 8.2),
,
.
8.2. MySQL
MySQL
mysql >
MySQL
->
'>
">
'>
,
(')
/*>
,
/*
, , , ,
Ctr+C! .
\ Enter.
8.1.
8.1.
mysql \
M ySQL
. \ .
: -
MySQL
195
, , \, ,
MySQL \ . 8.2 ,
\.
8.2.
" mysql " \
, \
, .
MySQL
SHOW,
, . . 8.3
.
8.3. MySQL
()
ALTER
BACKUP
\
CREATE
DELETE
DESCRIBE
DROP
EXIT (Ctrl+C)
GRANT
INSERT
LOCK
()
()
, EXIT
QUIT (\q)
RENAME
SHOW
SOURCE
STATUS (\s)
TRUNCATE
UNLOCK
()
()
UPDATE
USE
,
, MySQL.
196
8. MySQL
SQL .
CREATE, create . ,
,
.
Windows,
Linux Mac OS X.
.
.
,
,
. ,
,
publications :
CREATE DATABASE publications;
,
, Query OK, 1 row affected (0.38 sec) (
, 1 0,38 ), .
,
:
USE publications:
(Database changed),
.
, , MySQL,
, ,
, , ,
P H P - (root)
MySQL, , -
-.
GRANT, ( ,
):
GRANT ON _. _@_'
IDENTIFIED BY 11:
- , ,
..
, (. 8.4).
MySQL
197
8.4. GRANT
**
_*
_.
, ,
, (
jim mypasswd ):
publications
32-
Windows
64-
Windows
Mac OS X
/usr/local/zend/mysql/bin/mysql -u jim -p
Linux
mysql -u jim -p
, , ,
. ,
- ( ).
. , ,
,
..
, ,
GRANT. ,
. , ,
, , , , REVOKE,
: http://tinyurl.com/mysqlgrant.
, ,
IDENTIFIED BY, , -
, .
8. MySQL
198
MySQL, (ALL)
, publications ( ,
), .
,
( publications , ):
USE publications:
, 8.3.
8.3. classics
CREATE TABLE cla ssics (
author VARCHAR(128),
t i t l e VARCHAR(128),
type VARCHAR(16).
year CHAR(4)) ENGINE MyISAM;
---
--------------------------------------------------------------------------------------------- :
MySQL ,
, .
, ,
8.4,
.
8.4. MySQL:
mysql> USE publications;
Database changed
mysql> CREATE TABLE classics (
-> author VARCHAR(128).
-> t i t l e VARCHAR(128),
-> type VARCHAR(16).
-> year CHAR(4)) ENGINE MyISAM:
Query OK, 0 rows affected (0.03 sec)
mysql> DESCRIBE classics;
MySQL
199
8.3 ,
VARCHAR, CHAR. VARCHAR VARiable
length R acter string ,
, M ySQL ,
, .
, MySQL
.
: ,
, .
year () , VARCHAR
CHAR(4). 4
4 , -999 9999.
, , , ,
- ,
,
2000 - 1 2000
1900 .
200
8. MySQL
YEAR classics ,
0000 1901- 2155-. MySQL
1 , ,
256 , classics
.
, CHAR, VARCHAR, ,
. ,
CHAR . ,
. VARCHAR ;
,
. VARCHAR ,
. CHAR
, , a VARCHAR
,
. ,
VARCHAR , CHAR.
CHAR
. 8.6 CHAR.
, ( ) ,
. ,
. VARCHAR
255 1 , 256
2 .
8.6. CHAR, MySQL
CHAR(n)
(< 255)
CHAR(5) Hello 5
CHAR(57) New York 57
VARCHAR(n)
VARCHAR(IOO) Greetings 9
1
VARCHAR(7) Morning 7
1
(< 65 535)
BINARY
BINARY , ,
(. 8.7). ,
BINARY GIF.
8.7. BINARY, MySQL
BINARY(n)
BYTE(n)
(< 255)
CHAR,
VARBINARY(n)
(< 65 535)
VARCHAR,
201
MySQL
TEXT VARCHAR
TEXT VARCHAR .
5.0.3 M ySQL VARCHAR
, 256 .
TEXT .
TEXT MySQL (
).
, VARCHAR
, .
, , ,
TEXT (. 8.8).
8.8. TEXT, MySQL
TINYTEXT(n)
(< 255)
()
(< 65 535)
MEDIUMTEXT(n)
LONGTEXT(n)
BLOB
Binary Large Object ,
, , BLOB
, 65 536 .
BLOB BINARY , BLOB
(. 8.9).
8.9. BLOB, MySQL
TINYBLOB(n)
(< 255)
BLOB(n)
(< 65 535)
MEDIUMBLOB(n)
LONGBLOB(n)
MySQL ,
.
8 ,
, .
.
202
8. MySQL
. 8.10 , MySQL,
, .
, ,
.-: ,
.
, : ::
, , :
. , (
) .
8.10. , 5> =
( / )
( / )
TINYINT
-128
12 "
SMALLINT
-32 768
32 757
MEDIUMINT
-8 388 608
0
5 3SS 507
7 215
INT INTEGER
2 1 * "48 3647
* 29* 967 295
BIGINT
FLOAT
-3,402823466+38
( -'
3 ^2823466+38
)
DOUBLE REAL
-1,797693134862315^306
( ^
1.7976931348623157+308
)
, .
, UNSIGNED.
tablename, fie 'c ^ - e UNSIGNED INTEGER:
CREATE TABLE tablename (fieldname INT UNSI
>^
:
CREATE TABLE tablename (fieldname INT(4:
, BINARY CHAR
. : . ,
,
.
ZERC-FI_:
CREATE TABLE tablename (fieldname INT'-
I*^I__
.
,
MySQL
203
.
, .
DATE TIME
. 8.11 ,
MySQL, .
8.11. DATE TIME, MySQL
DATETIME
'0000-00-00
DATE
'0000-00-00'
TIMESTAMP
'0000-00-00 00:00:00'
00:00:00'
TIME
'00:00:00'
YEAR
, DATETIME TIMESTAMP,
. , TIMESTAMP ( 1970
2037 ), DATETIME ,
.
TIMESTAMP , , , MySQL
.
,
. MySQL
TIMESTAMP .
AUTO.INCREMENT
,
.
.
. ,
. , ,
. .
.
.
ISBN (International Standard Book Number
) classics,
AUT0_
INCREMENT.
, ,
,
. 8.5
, id classics
.
204
8. MySQL
8.5. id
ALTER TABLE classics ADD id INT UNSIGNED NOT NULL AUTOJNCREMENT KEY;
ALTER, CREATE.
ALTER ,
. id,
:
I NT UNSIGNED ,
, 4 ;
NOT NULL .
NULL,
- . ,
.
NULL ;
AUTO_INCREMENT M ySQL
, .
, ,
: , ,
;
KEY ,
.
.
id,
1,
. , id
.
,
, CREATE.
8.3 8.6.
.
8.6. id
CREATE TABLE classics (
author VARCHAR(128).
t i t l e VARCHAR(128).
type VARCHAR(16),
year CHAR(4),
id INT UNSIGNED NOT NULL AUTOJNCREMENT KEY) ENGINE MyI SAM:
, ,
, :
DESCRIBE classics:
, , i d
, , , 8.5,
, 8.7.
MySQL
205
8.7. id
ALTER TABLE classics DROP id:
INSERT.
, classics 8.1,
INSERT ( 8.8).
8.8. c l ass i c s
INSERT INTO classi cs(author. t itle , type, year)
VALUES('Mark Twain'.The Adventures of Tom S a w y e r F i c t i o n 1876');
INSERT INTO classics(author. t itle , type, year)
VALUES('Jane Austen'. 'Pride and Prejudice'. ' F ictio n '.'1811');
INSERT INTO classics(author. t itle , type, year)
VALUES( 'Charles Darwin' , 'The Origin of Species' . ' Non-Fiction'.'1856');
INSERT INTO classics(author, t itle , type, year)
VALUES('Charles Dickens' . 'The Old Curiosity Shop', 'F ic tio n '. '184);
INSERT INTO classics(author, t itle , type, year)
VALUES('William Shakespeare'. ' Romeo and J u lie t ', 'P lay','1594');
Query . ,
, :
SELECT * FROM classics;
, . 8.4.
. 8.4. classics
SELECT,
MySQL . ,
.
206
8. MySQL
, INSERT.
, INSERT INTO classics, MySQL,
. : author,
t it le , type year, .
M ySQL , .
INSERT VALUES,
,
. M ySQL ,
. (
,
, .)
. ,
.
.
,
, ALTER. , , ,
classics 1900. :
ALTER TABLE classics RENAME prel900:
, ,
, ,
:
ALTER TABLE prel900 RENAME classics:
ALTER,
MODIFY.
year CHAR(4) SMALLI NT (
2 , ),
:
ALTER TABLE classics MODIFY year SMALLINT;
, M ySQL ,
, .
,
.
,
, . . ,
pages,
, :
ALTER TABLE classics ADD pages SMALLINT UNSIGNED:
MySQL
207
pages, ,
UNSIGNEDSMALLINT, 65 535.
- !
M vSQL ,
DESCRIBE,
(. 8.5):
DESCRIBE classics:
. 8.5. pages
. 8.5, , type
, M ySQL
.
category:
ALTER TABLE classics CHANGE type category VARCHAR(16);
VARCHAR( 16) .
, CHANGE
, , VARCHAR( 16)
, type.
, , pages,
, ,
, DROP:
ALTER TABLE classics DROP pages:
, DROP ,
( )!
8. MySQL
208
.
cl assi cs, .
, ,
, , 8.9.
. 8.6.
8.9. ,
rai C:\Windows\system32\cmd.exe
11 1i ^
. 8.6. ,
cl assies,
, MySQL, .
, .
, MySQL
. ,
.
, ,
, , ,
. MySQL,
, MySQL
.
209
, . -
. , , , INDEX, PRIMARY
KEY FULLTEXT. , , ,
,
. ,
. ,
.
classics,
, .
pages, ,
, , ,
.
, ,
8.10.
8.10. classics
ALTER TABLE classics ADD INDEXCauthor(20));
ALTER TABLE classics ADD INDEX(title(20)):
ALTER TABLE classics ADD INDEX(category(4));
ALTER TABLE classics ADD INDEX(year);
DESCRIBE classics;
author
title , .
, M ySQL :
The Adventures of Tom Sawyer
20 :
The Adventures of
. 20 ,
,
. M ySQL ,
, ,
.
category, ,
, (F
Fiction, N Non-Fiction Play), ,
,
. (
, .)
210
8. MySQL
, year,
, .
( DESCRIBE, ,
) . 8.7,
MUL . ,
, , , ,
,
. .
. 8.7. classics
CREATE INDEX
ALTERTABLE, CREATE INDEX.
, , CREATE INDEX
PRIMARY
KEY (. ).
8.11.
8.11.
ALTER TABLE classics ADD INDEX(author(20)):
CREATE INDEX author ON classics (author(20));
, - . ,
. ,
classics .
8.12 8.3,
. , ,
, category
type, year SMALLINT,
211
CHAR(4).
cl assi cs cl assi cs , c la s s ic s l,
c la s sics l.
8.12. classics
c la s sics
, - .
,
, .
( )
, (.
:
9).
A U TO _IN CREM EN T
,
id , ,
.
: ISBN.
. , , ISBN 13 , ,
:
ALTER TABLE classics ADD isbn CHARC13) PRIMARY KEY:
. ,
, 1: Duplicate
entry. , ,
NULL , ,
, ,
. ,
,
.
:
, , 8.13.
, ,
212
8. MySQL
, ,
. 8.8. , ALTER
TABLE INDEX PRIMARY KEY (
8.10 8.13).
. 8.8. classics
^ cl assi cs,
, 8.14. ,
, classics 1 , .
8.14. classics
CREATE TABLE classics (
author VARCHAR(128),
t i t l e VARCHAR(128).
category VARCHAR(16).
year SMALLINT,
isbn CHAR(13).
213
INDEX(author(20)).
INDEX(ti tle ( 20)),
INDEX(category(4)).
INDEX(year).
PRIMARY KEY (isbn)) ENGINE MyISAM;
FULLTEXT
, MySQL FULLTEXT
, ,
, .
**
------------------------------------------------------------
- , MySQL FULLTEXT,
? d * ,
---- 500 ,
. ,
stopwords, the, as, is, of . . MySQL
FULLTEXT- .
.
FULLTEXT,
.
FULLTEXT MyISAM,
( ) M ySQL (M ySQL
).
MyISAM, MySQL:
ALTER TABLE tablename ENGINE = MyISAM;
FULLTEXT CHAR,
VARCHAR TEXT.
FULLTEXT CREATE TABLE
ALTER
TABLE ( CREATE INDEX).
,
FULLTEXT, , ,
FULLTEXT.
FULLTEXT, ,
8.15, FULLTEXT author
title , cl assi cs ( ,
, ).
8.15. FULLTEXT classics
214
8. MySQL
(,
), .
FULLTEXT
MATCH...AGAINST MySQL.
---
----------------------------------------------------------------------------------------------
MySQL ,
, .
-**? , , .
.
, 9 , ,
.
4
MySQL
, MySQL ,
, . ,
.
SELECT
. 8.4 , SELECT
.
, - ,
,
.
SELECT .
:
SELECT - FROM _;
-, , (*),
, -
. 8.16 , (author
t i t l ) ISBN.
. 8.9.
8.16. SELECT
SELECT author,title FROM classics;
SELECT title .isb n FROM classics:
SELECT COUNT
- COUNT,
. 8.17
(*), .
5, .
8.17.
SELECT COUNT(*) FROM classics:
215
j C:\Windows4v>ystem32\crrid.exe
I*=>
' claries;
*i
i 1;
1i,e
Ui
--; in
d C u r i o s i t y
.Rene and J y J i e t
Sh \
: F80M c Ia s s
. 8.9. , SELECT
SELECT DISTINCT
( DISTINCTROW)
, . , ,
, .
author , ,
,
. DISTINCT
. ,
,
( 8.18).
8.18.
INSERT INTO classics-:author, title , category, year, isbn)
VALUESC'Charles Dickens . Little D o rrit'. 'F ic tio n '. '1 8 5 7 ' . '9780141439969');
, ,
SELECT DISTINCT .
8.19 . 8.10 , SELECT
, DISTINCT
.
8.19. SELECT DISTINCT
SELECT author FROM classics:
SELECT DISTINCT author FROM classics:
DELETE
, DELETE.
SELECT,
, WHERE LIMIT.
216
8. MySQL
. 8.10. DISTINCT
, , 8.18,
DISTINCT, L it t le D orrit ,
8.20.
8.20.
DELETE FROM classics WHERE t it le = L it t le D orrit';
DELETE , t i t l
Li t t l Dorri t.
WHERE , ,
.
( , WHERE
).
, SQL.
WHERE
WHERE ,
,
. = 8.20
, t i t l e
L it t le Dorrit. 8.21 ,
WHERE =.
8.21. WHERE
SELECT a u th o r.title FROM classics WHERE author="Mark Twain";
SELECT a u th o r,title FROM classics WHERE isbn="9781598184891 ";
.
, , -
217
, ( ,
, ISBN ) The Adventures of Tom Sawyer.
, , ,
, ,
.
, LIKE,
.
% . ,
- , - .
8.22 ,
, , .
. 8.11.
8.22. LIKE
, ,
, LIKE
Charles, .
The Origin of Species,
, Species.
Pri de and Prejudi ce
Romeo and Jul iet,
and .
% ,
. , .
218
8. MySQL
LIMIT
LIMIT
, . ,
MySQL
, .
,
, M ySQL ,
, . ,
: , .
8.23 .
. , 1 (
). , 3 (
).
. 8.12.
8.23.
SELECT a u th o r.title
SELECT a u th o r.title
SELECT a u th o r.title
FROM classics
FROM classics
FROM classics
LIMIT
LIMIT
LIMIT
3:
1.2;
3.1:
. 8.12. LIMIT
UMIT ,
, . LIMIT 1,3
, .
MATCH...AGAINST
MATCH.. .AGAINST ,
FULLTEXT (. FULLTEXT).
, ,
219
, . .
*HERE. . .= WHERE.. .LIKE, MATCH...
AGAINST
, FULLTEXT. FULLTEXT
, ,
.
, FULLTEXT author t i t l e
, 8.24.
, and. and
. MySQL ,
, .
, : ol d shop.
tom sawyer.
. 8.13.
8.24. /
SELECT
WHERE
SELECT
WHERE
SELECT
WHERE
220
8. MySQL
+
, .
,
, ,
. , ,
, .
8.25 , .
, charl es
species. ,
, o rig in of. . 8.14
.
8.25. MATCH.. .AGAINST.. . IN BOOLEAN MODE
, , , The Old
Curiosity Shop . ,
,
species.
.
____ 4*4
- :
of, ,
.
221
UPDATE...SET
: .
:~: > : ,
, ,
-: , SELECT.
8.26 UPDATE.. .SET.
. 8.15.
8.2.
/:~: UPDAIE...SET
ORDER BY
ORZl2 z
51 .
8.27 ,
. 8.16.
222
8. MySQL
8.27. ORDER BY
SELECT a u th o r.title FROM classics ORDER BY author;
SELECT a u th o r.title FROM classics ORDER BY t i t l e DESC;
. 8.16.
,
( ),
.
,
( ),
:
SELECT au th or.title.year FROM cla ssics ORDER BY author.year DESC:
,
DESC
, , year. author
, ,
.
,
:
SELECT au th or.title.year FROM classics ORDER BY author ASC.year DESC;
GROUP BY
, ORDER BY, ,
, GROUP BY,
. ,
, class'cs,
SELECT category.COUNT(author) FROM classics GROUP BY category:
223
:
. + ------------
category
| C0UNT(author)
- + --------------------------
Classic Fiction 1
Non-Fiction
1
Play
1
.+
1
1
------------------
,
, . , ,
customers,
cl ass i cs.
, 8.28. . 8.17.
8.28. customers
CREATE TABLE customers (
name VARCHAR(128),
isbn VARCHAR(128).
PRIMARY KEY (isbn)) ENGINE MyISAM:
INSERT INTO customers(name.isbn)
VALUESCJoe Bloggs . '9780099533474 ):
INSERT INTO customers(name.isbn)
VALUESCMary Smith', '9780582506206'):
INSERT INTO customers (name, isbn.)
VALUESCJack W ilson'. '9780517123201'):
SELECT * FROM customers;
j Eg C:\Windows\system32\cmd.exe
si
1
1
IH
1
R
^ ]
u J if , > ;
n<?.ne
1 is-hrt
i Jo
;
<;n,i.r.h
i J a c k U ils o n
j v ? 8 009 v b 33474
1 9?a058250b28S
; 9780 7123201
;
;
i
. 8.17. customers
224
^
fS x
' _U
8. MySQL
, , ,
, , . .,
.
,
- classics: isbn.
(ISBN
),
, 8.29.
8.29.
SELECT
-+------------| author
| t it le
, ,
classics,
customers?
NATURAL JOIN
NATURAL JOIN,
. ,
.
, 8.29, :
SELECT name.author.title FROM customers NATURAL JOIN classics:
JOIN...ON
, ,
JOIN.. .ON,
, 8.29:
225
AS
AS.
AS, .
, 8.29:
SELECT name.author.title from
customers AS cust. classics AS class WHERE cust.isbn=class.isbn;
:
+---------------+---------------------- +------------------------------+
| name
| author
|t it le
+---------------+---------------------- +------------------------------+
| Joe Bloggs| Charles Dickens |The Old Curiosity Shop |
j Mary Smith | Jane Austen
j Pride and Prejudice
j
j Jack Wilson j
Charles Darwinj The Origin of Speciesj
+---------------+---------------------- +------------------------------+
3 rows in set (0.00 sec)
,
.
MySQL,
WHERE, AND, OR NOT.
8.30 ,
.
8.30.
226
8. MySQL
MySQL
M ySQL
. :
MySQL .
MySQL,
, .
M ySQL
, .
URL-:
: http://tinyurl.com/mysqlstrfuncs:
: http://tinyurl.com/mysqkJatsfjncs.
.
MySQL phpMyAdmin
MySQL, ,
, , ,
phpMyAdmin.
,
, publications
cl assi cs customers ,
.
Windows
,
, Zend Server . ,
M ySQL :
http://1ocalhost/phpMyAdmi n
, . 8.18,
zend ( )
. , . 8.19.
phpMyAdmin.
Mac OS X
, Zend Server
Apache MySQL, :
http://1ocalhost:10081/phpmyadmi /
227
MySQL phpMyAdmin
# 1 http://localhost P - <SX
:
File
Edit
View
Fgvorites
Tools
. phpM yAdm in
X Ij&aS&J
Help
phpMyAdmin
Welcome to phpMyAdmin
-Language-----------------------------------------
| E nglish___________________
[[
-Log in -----Username:
zend
Password:
1. 9-1
^100% *
. 8.18. phpMyAdmin
i
file
. & http://localhost/phpMyAdmin/index.php?t
dt
Vkw
Fflvorites
Iools
P 8 X
tl^ P
I localhost
informatkm_schema (28)
my?iql(23)~
lest
gb Databases
^SQL
^Privileges
Ij, Replication
Status , fg|Variables
^Processes
Actions
f<j|Charsets
gfoExport
^Synchronize
MySQL
? Change password
Please select a database
ggEngines
jgp)Import
Logout
community
Protocol version: 10
User root@loca(host
MySQL localhost
|r| ( Create 1
Webserver
Interface
SP Language :
|English
Apache/2.2.21 (Win32)
mod_ssl/2.2.21
OpenSSL/O.9.80
MySQL client version:
mysqind 5.0.8-dev 20102224 -SRevision:
318113$
PHP extension: mysqli_____
^100% *
. 8.19. phpMyAdmin
228
8. MySQL
10081 Zend
, , phpMyAdmin.
, . 8.18,
zend ( ) .
, . 8.19,
phpMyAdmin.
Linux
Zend Server MySQL, phpMyAdmin
:
https -.//local host: 10082/phpMyAdmin
, . 8.18.
zend ( ) ,
. 8.19. .
phpMyAdmin
phpMyAdmin,
, Databases (
) publications,
, .
cl assi cs, ,
(. 8.20).
,
, , .
phpM yAdm in http://www.
phpmyad mi n.net/documentation/.
,
.
M ySQL ,
,
MySQL.
, SQL-,
MySQL.
1. MySQL?
2.
?
229
&
{Empty
(S 1 P I5 P I
Database
pubfccabons (2)
j publications (2)
*
9 customers
.P Search
^In sert
(Export
03Import
category varchar(16)
Attributes
NULL
Yes
NULL
SB
Yes
No
NULL
03
j?
Indexes:
E s
s &
Iatm1jswedish_a
'
Adtpn
X EB
year
smaKrip
is bn
char(13)
Iatm1_swedisti_a
t _ Check All / Uncheck All With selected:
Keyname
PRIMARY
Type
PRIMARY
INDEX
v u fo a rjtl FULLTEXT
*
Create an index on 1
\. E
> x
- |,<aQ,,,|
Space usage
CanflnaWy
5
$
me
INDEX
catej|0ty <
year
Type
Coffation
varchar(128) Iaftn1_swedish_a
varctef(128) tetini_swe<fishd
II
^Operations
IS Drop
Flehl
author
title
....... p i!
OSBrowse:
&
C" j
ft
Action
S X
Reid
isbn
Type
Data
Usage
4
X
X
X
author
20
title
20
category 4
Index
Total
7,592
None
None
None
f
S
f
None
year
None
aiihor
fife
'
cotomnsfGo~|
Done
3. MySQL newuser
newpass,
newdatabase?
4. ?
5. MySQL?
6. FULLTEXT?
7. ?
8. , SELECT DISTINCT GROUP BY,
,
. SELECT DISTINCT
GROUP BY?
9. SELECT.. .WHERE ,
- author cl assi cs,
, Langhorne?
10. ,
?
,
8.
MySQL
8
SQL.
, , , .
, ,
, . ,
, .
,
.
, ,
, , ,
, M ySQL
.
, , ,
.
-
.
, ?
?
?
?
?
?
?
- ?
231
,
, ,
.
, ISBN , ,
, (
).
,
.
, ,
.
- ,
. -
, .
, ,
.
authors (). ,
, ,
. ,
, ,
authors.
books (). .
, .
,
.
customers (). ,
,
.
,
, . ,
, ,
,
. ,
.
. .
: .
ISBN, , ,
,
ISBN.
232
9. MySQL
, AUTO INCREMENT, ,
, .
, -
, , , ,
, ,
. ,
. ISBN
,
, .
,
AUTOJNCREMENT.
. ,
.
,
.
,
, ,
.
, , ,
,
,
. ,
ISBN.
, ,
.
,
, ,
. ,
,
,
.
, ,
, . 9.1, ,
, .
, ,
.
, (
),
.
233
9.1.
ISBN
Price
Cust. name Cust.
() (
address
) (
)
Purch.
date
(
)
D a v id S k la r A d a m
0596101015
44,99
Mar 03
2009
T ra c h te n
PH P
C ookbook
Emma
Brown
1565
Rainbow
Road, Los
Angeles, CA
90014
b e rg
Dynamic
HTML
0596527403 59,99
Darren
Ryder
0596005436 44,95
Earl B.
Thurston
Darren
Ryder
David Miller
3647 Cedar
Lane,
Waltham,
MA 02154
Danny
Goodman
Hugh E.
Williams
D a v id S k la r A d a m
T ra c h te n
PH P
0596101015
44,99
C ookbook
b e rg
Rasmus
Lerdorf
Kevin
Tatroe
& Peter
MacIntyre
Program
ming PHP
0596006815 39,99
Jan 16
2009
,
,
,
.
,
.
1. ,
.
2. .
3. .
, , Author 1
Author 2 . ,
, ,
Author 1.
, , Programming ,
. , Author 2
Kevin Tatroe Peter MacIntyre 2.
.
234
9. MySQL
3 , ISBN
.
. 9.2 . 9.1.
, ,
.
9.2. Authors . 9.1
Title
()
ISBN
Price ()
Purch.
Cust. Address
Cust. name
( ( Date (
)
)
)
C ookbook
0596101015
44,99
Emma Brown
Dynamic HTML
0596527403
59,99
Dec 19 2008
and
MySQL
0596005436
44,95
Earl B.
Thurston
Jun 22 2009
PH P C ookbook
0596101015
44,99
Programming
PHP
0596006815
39,99
David Miller
1565 Rainbow
Road, Los
Angeles, CA
90014
862 Gregory
Lane, Frankfort,
KY 40601
Mar 03 2009
Dec 19 2008
Jan 16 2009
Authors . 9.3,
. ISBN,
, .
,
,
, . : MySQL
. ,
, M ySQL ISBN
, - .
9.3. Authors
ISBN
Author ()
0596101015
David Sklar
0596101015
Adam Trachtenberg
0596527403
Danny Goodman
0596005436
Hugh E Williams
0596005436
David Lane
0596006815
Rasmus Lerdorf
0596006815
Kevin Tatroe
0596006815
Peter MacIntyre
235
, ISBN
Books, . ,
, ISBN
Authors. Authors
,
.
Authors ISBN ,
, , ,
.
, : ISBN
,
.
, .
( ) MySQL .
4 . 8
----
, WHERE .
. ,
.
( ) .
.
,
.
, ,
,
.
. 9.2. , Darren Ryder
, . , ,
(Customer name Customer address),
. . 9.4 ,
, . 9.2.
9.4. Titles
ISBN
Title ()
Price ()
44,99
0596101015
Cookbook
0596527403
Dynamic HTML
59,99
0596005436
44,95
0596006815
Programming PHP
39,99
236
9. MySQL
ISBN
Cust Name
( )
Cust. Address
( )
Purch. Date
( )
0596101015
Emma Brown
Mar 03 2009
0596527403
Darren Ryder
Dec 19 2008
0596005436
Earl B. Thurston
Jun 22 2009
0596101015
Darren Ryder
Dec 19 2008
0596006815
David Miller
Jan 16 2009
,
, . ISBN
( ), .
. 9.6 Customers
.
, CustNo,
, ,
AUTO INCREMENT.
,
.
237
9.6. Customers
CustNo
(
)
Name ()
Address
()
City ()
State ()
Zip (
)
Emma Brown
1565 Rainbow
Road
Los Angeles
CA
90014
Darren Ryder
4758 Emily
Drive
Richmond
VA
23219
Earl .
Thurston
862 Gregory
Lane
Frankfort
KY
40601
David Miller
3647 Cedar
Lane
Waltham
MA
02154
. 9.6
,
.
Purchases (. 9.7).
9.7. Purchases
CustNo ( ) ISBN
Date ()
1
2
2
Mar 03 2009
0596101015
0596527403
Dec 19 2008
0596101015
Dec 19 2008
0596005436
Jun 22 2009
0596006815
Jan 16 2009
, Customers Purchases,
CustNo . 9.6.
ISBN, Authors,
Titles.
CustNo ( )
Purchases:
( ), CustNo
. Purchases
. ,
.
, ,
.
, , , CustNo ISBN.
---
----------------------------------------------------------------------------------------------
, , ,
*<SV4 * .
, ,
Purchases ().
238
9. MySQL
, , ,
- .
,
, , ,
,
, ,
.
, . 9.6, Customers, , State,
Ci ty Zi code ,
.
, Address
City, State.
, . 9.6,
. 9.8-9.11.
9.8. Customers,
CustNo
(
)
Name ()
Address ()
Zip
(
)
1
2
Emma Brown
90014
Darren Ryder
23219
Earl . Thurston
40601
David Miller
02154
239
Zip ( )
CitylD ( )
90014
1234
23219
5678
40601
4321
02154
8765
9.10. Cities,
CitylD (
)
Name ()
StatelD (
)
1234
Los Angeles
5678
Richmond
46
4321
Frankfort
17
8765
Waltham
21
9.11. States,
StatelD (
)
Name ()
Abbreviation
()
California
CA
46
Virginia
VA
17
Kentucky
KY
21
Massachusetts
MA
9.6? . 9.8 Zip-, . 9.9
. , . 9.10 ',
StatelD, . 9.11
.
, . ,
. 9.11, ,
.
.
t3 f
---
----------------------------------------------------------------------------------------------
9.10 4 * , () .
-*#?* , ,
.
,
, . ,
.
, , , , ,
, .
240
9. MySQL
, ,
, . ,
? , . 9.6,
, .
,
. 9.10 ,
.
,
,
.
1. ,
?
2. -
?
, , ,
.
, ,
, ,
. ,
( , ), ,
, ,
MySQL.
,
, ,
MySQL. , ,
, ,
.
, ,
.
,
,
. ,
,
, (),
,
, .
, . MySQL
(triggers),
. ( .)
241
PH P-
.
. (
MySQL .)
MySQL,
,
.
MySQL .
MySQL ,
, .
.
:
. . ,
, ,
. , ,
,
.
, , , - .
Customers-Addresses . 9.1
: ,
.
, ,
.
:
, ;
, ,
.
, ,
,
( , ).
( ) ,
.
, . 9.8 ,
242
9. MySQL
.
.
9.8, a (Customers)
9.8,
(Addresses)
Addre$&
23219
40601
02154
90014
. 9.8, , . 9.1, ,
, . 9.7,
. 9.8, .
. 9.7, Purchases, ( ) ,
.
.
. 9.2 ,
, ,
.
,
.
9.8, a (Customers)
9.7 (Purchases)
CustNo
ISBN
Date
Emma Brown.................. .. 1
0596101015
Mar 03 2009
0596527403
Dec 19 2008
L ..... 2
0596101015
Dec 19 2008
Earl B. Thurston.............. .. 3
0596005436
Jun 22 2009
0596006815
Jan 16 2009
Custblo
Name
1
2
. 9.2.
. ,
, ,
243
. ,
.
. 9.12.
. 9.7, Purchases (),
. ISBN ,
.
9.12.
Customer ()
ISBN
1
2
2
0596101015
0596527403
0596101015
0596005436
0596006815
, .
, ,
.
, , ,
23219. (zip code) . 9.8, ,
, 2
, . . 9.8, ,
. 9.12,
.
, , ,
. 9.4, . 9.3
.
, , , ,
, . ,
. 9.3 .
9.8,
(Customers)
9.4
(Titles)
9.12
(Customers/ISBN)
Zip
Cust
90014
1 ------- 1
2 ---- ~ - - 2
L 2
40601
......... 3
02154
Programming PHP
23219
CustNo
ISBN
ISBN
Title
PHP Cookbook
0596527403 .....
Dynamic HTML
. 9.3.
244
9. MySQL
(zip-)
.
,
ISBN.
ISBN , ,
.
zip-. Titl es
ISBN,
, , , Customers
zip-
.
, , , ,
. ,
zip- ,
.
,
,
.
,
. , ,
. ,
- .
,
, ,
.
,
.
,
, , .
?
. ,
, ?
, MySQL ,
.
245
,
,
, , M ySQL
.
( )
MySQL ,
M ySQ L- InnoDB. ,
.
, , 9.1. (
, M ySQL
.)
9.1. ,
CREATE TABLE accounts (
number INT, balance FLOAT. PRIMARY KEY(number)
) ENGINE InnoDB;
DESCRIBE accounts;
, ,
, .
:
+----------- +----------+-------+-------+----------+---------+
| Field
| Type
| Null | Key
|Default| Extra |
| NO
| YES
| 0
|NULL
+----------- +----------+-------+-------+----------+---------+
| number | in t ( ll)
| balance | flo a t
| PRI
|
|
|
|
|
+----------- +----------+-------+-------+----------+---------+
2 rows in set (0.00 sec)
,
. , 9.2.
9.2. accounts
INSERT INTO accounts(number, balance) VALUES(12345. 1025.50);
INSERT INTO accounts(number, balance) VALUES(67890, 140.00);
SELECT * FROM accounts;
,
. :
+--------- +-----------+
| number | balance |
+--------- +-----------+
| 12345 | 1025.5 |
|
67890 |
140 |
+--------- +-----------+
2 rows in set (0.00 sec)
246
9. MySQL
BEGIN
M ySQL BEGIN, START
TRANSACTION. MySQL, ,
9.3.
9.3. MySQL
BEGIN;
UPDATE accounts SET balance=balance+25.11 WHERE number=12345;
COMMIT;
SELECT * FROM accounts;
,
, :
+---------+---------- +
|
number |balance |
+---------+---------- +
|
12345 |1050.61 |
| 67890 |
140 |
+---------+---------- +
COMMIT
, , ,
, COMMIT, .
COMMIT,
MySQL . ,
COMMIT ROLLBACK.
ROLLBACK
ROLLBACK, M ySQL ,
.
, 9.4.
BEGIN;
UPDATE
UPDATE
SELECT
9.4.
accounts SET balance=balance-250 WHERE number=12345;
accounts SET balance=balance+250 WHERE number=67890;
* FROM accounts;
247
EXPLAIN
, :
+---------+--------- +
|
number | balance |
|
|
12345 | 800.61 |
67890 |
390 |
+---------+--------- +
+ ------------------------- + --------------------
250 ,
, 250
250 . , -
. ,
9.5.
9.5. / :
ROLLBACK
ROLLBACK;
SELECT * FROM accounts:
,
,
ROLLBACK:
_ ---- + .
number | balance
12345 | 1050.61
140
67890 |
2 rows in set (0.00 sec)
EXPLAIN
MySQL ,
, .
EXPLAIN, , ,
.
accounts 9.6.
9.6. EXPLAIN
EXPLAIN :
+------ +--- +--------- +-----+----- +---- +---+--- +
\ ' z \ se'ect_type|ta b l
|key_len|ref
|rows|Extra|
| 1 51_
|PRIMARY 14
|const |
1|
248
9. MySQL
M ySQL :
select_type. SIMPLE.
(join) ;
table. accounts;
type. const. ,
: ALL, index, range, ref, eq_ref, const, system
NULL;
possi bl e_keys. , , PRIMARY, ,
;
key. PRIMARY,
;
key len. 4. ,
MySQL;
ref. ref ,
. ;
rows. , ,
1, .
,
, EXPLAIN, ,
. , (
) , . .,
( ).
accounts , mS' 4 * :
<
, ,
,
,
.
.
,
.
, .
M ySQ L
mysqldump.
249
mysqldump
mysqldump
, ,
.
CSV
(Comma-Separated Values) ,
, X M L -.
, ,
. ,
M ySQL:cepBepa mysqldump
.
mysql dump
. ( )
M ySQL :
LOCK TABLES _1 READ, _2 READ ...
:
UNLOCK TABLES:
mysqldump
, ,
>.
mysqldump :
mysqldump - - _
, , ,
mysqldump
. . 9.13
, 2. -
, .
9.13. mysqldump
ZendServerCE 32-
Windows
C:\Pro0ram Files\zend\MySQL51\bin
ZendServerCE 64- .
Windows
C:\Program Files(x86)\zend\MySQL51\bin
OS X Zend Server
/usr/local/zend/mysql/bin
/usr/local/zend/mysql/bin
publications, 8,
mysql dump ( )
, 9.7.
9. MySQL
250
- - pu b lica tio n s
,
MySQL.
, , -
,
(root) (
). ::-: ,
. 9.4.
2| C:\Window5\5y5tem3Z\cmd.exe
>
. = - ii
DEFAULT CHARSET = 1 a t in 1 ;
LO CK
T S iiL I - S
INSEKT
B8 5 i V l 2 3 2 e t >;
s *M 8 0 0 0 f l L i a
UNLOCK TABLES;
>'<*18103
S I-1
. ' c u c t o n e iv : '
T IM E
ENaiiLE KEVS
*\
Z O K E ^ O L D . . . . T I M E . ..Z O N E .
Dum p
co n p Ie * d
|C : \ P t 4 w r a n
on
F iI e S F . a s * # P H F
-
3 .
'--'0
I;
i
1.1 : i i } : 4 i >
>
. 9 .4 . publications
mysqldump .
, ,
>.
,
' cati ons.
sql , , 9.8 (
).
9.8. public a v : - s
Zz?r
, -
9.8 .
4 * - , ----
. , , ,
, ,
.
, SQL-:
251
,
, ,
, ,
MySQL.
(
classics publications),
MySQL , :
LOCK TABLES p ub lications.classics READ;
MySQL , .
, MySQL, ,
:
mysqldump - - publications classics > classics.sq l
,
MySQL ,
, :
UNLOCK TABLES;
MySQL
( , mysql), ,
9.9,
MySQL, , .
9.9. MySQL
&
, MySQL SQL? 4 .
---- ^
, , .
252
9. MySQL
,
mysql , ,
<. ,
--all-databases, ,
9.10.
9.10. " 5 -*
-D,
. 9.11 ,
publ i cati ons , ,
9.8.
9.11. publicat"ors
,
9.12, pub! i cati ons
cl assi cs.
9.12. classics publications
CSV
, mysql dump
, CSV.
9.13 , cl assi cs customers
publications c la s s ic s .tx t customers.txt,
: /temp. Zend Server
root .
OS X Linux,
.
9.13. CSV
, ,
.
:
Mark Twain (Samuel Langhorne Clem ens)'The Adventures
of Tom Sawyer . 'C lassic F ic t io n '.'1876'.'9781598184891
Jane Austen , 'Pride and P re ju d ice ', 'C lassic F ic t io n '.'1811','9780582506206
Charles Darwin','The Origin of Species . 'N o n -F ictio n ','1856'.'9780517123201
Charles Dickens'. 'The Old Curiosity Shop'. 'C lassic F ic t io n '.'1841','9780099533474
253
,
, . ,
. ,
.
, .
df
. ,
. ,
, ;
, , - DVD . .
, - .
, MySQL. ,
.
1. (relationship)
?
2.
?
3. ?
4. ?
5. , ,
, ?
6. ?
7. MySQL?
8. M ySQL
?
9.
pub! ic a ti ons publ icati ons. sql ?
,
9.
1 0 MySQL
X I #
MySQL, . ,
MySQL.
MySQL
MySQL
SQL- ,
-.
M ySQL ,
MySQL
, MySQL. MySQL
, ,
, .
-.
M ySQL .
1. MySQL.
2. , .
3. .
4. .
5. -.
6. 3- 5- .
.
7. MySQL.
MySQL
255
,
, ,
,
.
-, ,
, MySQL, ,
.
, , . ,
1ogin. php, 10.1. ,
_ ,
MySQL, , , , 2.
. 1ocal host
, M ySQL
, publications,
.
10.1. login.php
<?php // login.php
$db_hostname = 'localhost';
$db_database = 'publications';
$db_username = ' _' ;
$db_password = '':
?>
1ogi n. php, 10.1,
<?php ?>, , ,
, .
, -
, . ,
. -
-.
$db_hostname ,
. ,
M ySQL ,
, ,
. ,
, .
mysql.myserver.com,
localhost ( 1- 127.0.0.1).
, $db_database,
publications, , , , 8,
, (
1ogi n.php).
10. MySQL
256
$db_username $db_password
, MySQL.
, ,
,
, PHP-,
MySQL.
MySQL
login.php require_
P H P -, .
, i ncl ude, ,
, . ,
,
, .
requi _, reqi.'re ,
, - ,
. ,
, 10.2.
once
10.2. MySQL
<?php
requi re_once 1ogi n .php ;
$db_server = mysql_connect($db_hostname. Scz^se^rame. $db_password);
if
( !$db_server) die("HeB03M0>KH0
?>
- mysql connect,
: (hostname) M ySQ L -, (username)
(password).
, FALSE.
, i f
die, ()
, Sdb server
.
, die, ,
M ySQ L ,
, mysql_error.
,
M ySQL.
, $dbserver,
MySQL.
M ySQL -.
MySQL
257
die , , ,
, .
, ,
, :
function mysql_fatal_error($msg)
{
$msg2 - mysql_error();
echo < _END
, .
:
<p>$msg: $msg2</p>
,
. ,
. < href=Mmailto:admin@server.com">coo6iiiHTe
</>. .
END:
)______________________________________________________________
M ySQL
, . , 10.3.
10.3.
<?php
mysql_select_db($db_database)
or di(" : " . mysql_error());
?>
mysql_select_db.
, .
die.
, ,
mysql _sel ect_db, TRUE, FALSE.
P H P - or, :
, ,
. , or
.
MySQL mysql_
query. 10.4.
10.4.
<?php
$query = "SELECT * FROM classics":
258
10. MySQL
$result = mysql_query($query);
, mysql_query,
.
mysql _result. 10.5
,
.
, 1ogi n.php,
query. php.
10.5.
<?php // query.php
requi re_once '1ogi n.php ;
$db_server = mysql_connect($db_hostname. $db_username. Sdb_password);
if
( !Sdb_server) die("HeB03M0MH0
mysql_select_db($db_database)
or die("HeB03M0>KH0 : " . m ysql_ error()) ;
Squery = "SELECT * FROM classics":
Sresult = mysql_query(Squery):
i f ( ! Sresult) die (" : " . mysql_error()):
Srows = mysql_num_rows(Sresult):
for (Sj = 0 ; Sj < Srows : ++Sj)
259
MySQL
echo
echo
echo
echo
echo
'Author: '
. mysql_result($result,$j, 'author')
'<br
'Title: '
. m ysql_result($result,$j.'title')
'<br
'Category: ' .mysql_result($result,$j. 'category') . '<br
'Year: '
. mysql_result($result,$j.'year')
'<br
'ISBN: '
. mysql_result($result,$j. ' isbn*)
'<br /><br
/>';
/>';
/>';
/>':
/>':
}
?>
,
. $rows ,
mysql num rows.
, .
, for,
mysql resul t.
$result, mysql_
query, $j , .
, mysql _resul t,
echo
.
. 10.1.
Mozitla Rrefox
..
v.
fiookmwte ..
...........................| ( D
I http://localho5t/wefa/quMy.php
v:.
Q .
260
10. MySQL
, , , 8 classics
, , , query.php .
,
25 mysql result.
, mysql_fetch_row
.
9 , ,
, classics ,
, . ,
, .
MySQL
,
.
M ySQL
, .
for query. php (. 10.5) ,
10.6, , ,
. 10.1.
for
<?php
for ($j = 0 ; $j < Srows ; ++$j)
{
$row = mysql _fetch__row($result):
echo 'Author: '
$row[0] . ' <br / > ':
echo 'Title: ' .
Srow[l] . <br / > ':
echo 'Category: '
$row[2] . '<br / > ':
echo 'Year: '
$row[3] . '<br /> :
$row[4] . '<br /><br />
echo 'ISBN: '
}
?>
10.6.
, MySQL,
( 80 %) , mysql_fetch_row
. ,
$row.
$row ( ). , $row[0]
, $row[l] . .,
, MySQL.
mysql_result mysql_fetch_row
,
,
.
261
.
, 10.7.
10.7. MySQL
<?php
mysql_close($db_server);
?>
,
mysql _connect 10.2 $db_server.
sif
,
4 *, / 10.5 , .
!
,
,
.
M ySQL .
10.8
sqltest.php. ,
. 10.2.
10.8 HTML-. ,
.
uf'4j L
10.8. sqltest.php
<?php // sqltest.php
require_once 'login.php';
$db_server = mysql_connect($db_hostname. $db_username, $db_password);
i f ( !$db_server) die(" MySQL: " . mysql_error());
mysql_select_db($db_database. $db_server)
or die(" : " . mysql_error());
i f (isset($_P0ST['delete']) && isset($_P0ST['isbn']))
{
$isbn = get_post('isbn'):
$query = "DELETE FROM classics WHERE isbn='$isbn'
i f (!mysql_query($query, $db_server))
262
10. MySQL
Mozilla Firefox
|
. ^ goobnarie
Io o ls
S k
gdp
in i ( D
Q
|http://localhost/web/sqltest.php
" I ( E H 600^ *
P \\,
A u th o r
f l
T itle
C a te g o ry
I
Year
ISB N
;
;
J
1 A Q P B E C Q R P .I
A u th o r
T itle
C a te g o ry
Y ear
ISB N
[
A u th o r
T itle
C a te g o ry
Y ear
IS B N
H a r k T w a in (S a m u e l L a n g h o r n e C le m e n s )
The A d v e n t u r e s o f Tom S aw y e r
C la s s ic F ic tio n
187 6
9781598184891
Ja n e A u s te n
P r id e a n d P r e ju d ic e
C la s s ic F ic tio n
181 1
9780582S06206
ImeiEMCoRel
A u th o r
T itle
C a te g o ry
Y ear
C h a r l e s D a r w in
The O r i g i n o f S p e c ie s
N o n - F ic tio n
185 6
Done
#>
. 10.2. , 10.8,
sqltest.php
263
}
echo <_END
<form action="sqltest.php" method="post"><pre>
Author <input type="text" name="author" />
Title <input type="textn name=,,title " />
Category <input type="text" name=,,category" />
Year <input type=,,text" name=M
year" />
ISBN <input type="text" name="isbn" />
<input type="submit" value="ADD RECORD" /> //
//
</pre></form>
_END;
Squery = "SELECT * FROM classics";
$result = mysql_query(Squery);
i f ( ! Sresult) die (" : " . mysql_error());
Srows = mysql_num_rows(Sresult);
for ($j = 0 ; $j < Srows ; ++$j)
{
Srow = mysql_fetch_row($result):
echo <_END
<pre>
Author $row[0]
Title $row[l]
Category $row[2]
Year $row[3]
ISBN $row[4]
</pre>
<form action="sqltest.php" method="post">
<input type="hidden" name="delete" value=nyes" />
<input type="hidden" name="isbn" value="$row[4]" />
<input type="submit" value="DELETE RECORD" /></form>
//
//
_END:
}
mysql_close($db_server):
function get_post($var)
{
return mysql_real_escape_string($_POST[$var]);
}
?>
80
,
10.5, .
264
10. MySQL
,
classics publ ications, .
, ,
. , .
isset,
, .
,
if, get post,
. , :
.
$_POST
3 ,
GET- POST-. POST-,
. - (
) $_P0ST. .
$_P0ST , 6.
$_P0ST S GET
, , POST GET.
.
, .
, i sbn, S P0ST
isbn. P H P - ,
$_P0ST['isbn'], $_P0ST["isbn"] (
).
$_P0ST ,
, 10.8:
, $_P0ST
. PH P- :
S P0ST .
&
$_POST .
4 ,
#? .
get post, ,
mysql_real_escape_string,
,
.
,
, ,
265
$_POST[ 'delete' ]. , ,
DELETE RECORD ( ).
Sisbn.
, ISBN
. H T M L- ISBN DELETE FROM,
Squery, mysql query,
MySQL. mysql_query TRUE, FALSE,
FALSE ,
.
Sdelete yes (),
else. Squery INSERT INTO,
.
mysql query,
TRUE, FALSE. FALSE,
.
, ,
. 10.2. echo <_END,
, END,
.
echo ,
?>, HTML, ,
<?php. ,
PHP- :
( )
, .php .
HTML;
HTML,
. HTML
, , HTML.
H T M L - , ,
sqltest.php. ,
sql test, php, .
POST-, GET-. ,
GET- U R L -
.
.
POST-,
, .
HT M L Submit
ADD RECORD ( ), .
266
10. MySQL
<> </>,
.
<> ,
.
10.5,
M ySQL
classics. Srows ,
,
for.
. <br />,
10.5 ,
<>, ,
.
,
sql te s t. php ( ),
: delete isbn. delete yes,
isbn , $row[4],
ISBN . Submit
DELETE RECORD ( ), .
for, ,
.
get post,
. P H P -,
MySQL. ,
.
( )
Moby Dick,
:
Herman Melville
Moby Dick
Fiction
1851
9780199535729
ADD RECORD (
), - ,
. . 10.3.
, ,
. 1
ADD RECORD ( ).
267
MySQL
, , . ,
, DELETE RECORD
( ) , ,
.
Mozilla Fi refox
file drt
)ifcm
' X ^ Q
j?. ( D Ihttp://localhost/web/sqltest.php
won-nccxon------ ~
----------
c a t e g o r y
Y e ar 1856
ISBN 9780517123201
>
ft - HEMax***
p\
------------- ------------------
| DELETE RECORD |
Author
Ti tl e
Ca te go ry
Ye ar
ISBN
Charles Dickens
The Ol d C u ri os it y Shop
Cl as si c Fi ct io n
1841
9780099533474
[ DELETE RECORD |
Au th or
Ti tl e
Ca t e g o r y
Ye ar
IS BN
W i l l i a m Sh akespeere
Romeo and Juliet
Play
1594
9780192814968
[ DELETE RECORD |
Author
Ti tl e
Ca t e g o r y
Year
I S BN
e ;|
H e rm an Me lv il le
M o b y Dick
Fiction
1851
97 80 199535729
| DELETE RECORD |
Done
. 1 0 .3 . M o b y Dick
^ --hV
---------------------------------------------------------------------------------------------
, , .
, (
Moby Dick) , .
, , ,
, ,
ISBN, .
MySQL
,
MySQL,
, , ,
- . ,
, 1ogi . php,
.
268
10. MySQL
,
. ,
: , , , , , ,
, .
. , .
, .
, ,
, , ,
, .
, id.
10.9 ,
MySQL, . ,
, .
10.9.
cats
<?php
require_once 'login.php';
$db_server = mysql_connect($db_hostname. $db_username. $db_password):
i f ( !$db_server) die(" MySQL: " . mysql_errorO):
mysql _select_db($db_database)
or die("HeB03M0>KH0 : " . mysql_error()):
$query = "CREATE TABLE cats (
id SMALLINT NOT NULL AUTOINCREMENT,
family VARCHAR(32) NOT NULL,
name VARCHAR(32) NOT NULL,
age TINYINT NOT NULL.
PRIMARY KEY (id)
)":
Sresult = mysql_query($query):
i f ( ! Sresult) die (" : " . mysql_error()):
?>
, M ySQL- ,
, ,
, MySQL
.
MySQL,
,
. DESCRIBE _ ,
H T M L-, : Column (), (),
Nul 1 () Key (),
MySQL
269
. 10.10 ,
cats .
10.10. cats
<?php
require_once 'login.php';
$db_server = mysql_connect(Sdb_hostname, $db_username, $db_password);
i f ( !$db_server) die(" MySQL: " . mysql_error());
mysql_select_db($db_database)
or die(,,Heooo : " . mysql_error()):
$query = "DESCRIBE cats";
Sresult = mysql_query(Squery);
i f ( ! Sresult) die (" : " . mysql_error()):
Srows = mysql_num_rows(Sresult):
echo "<table><tr> <th>Column</th> <th>Type</th>
<th>Nul1</th> <th>Key</th> </tr>";
for (Sj = 0 : Sj < Srows : ++$j)
{
Srow = mysql_fetch_row(Sresult);
echo "<tr>":
for (Sk = 0 : Sk < 4 ; ++Sk) echo "<td>Srow[Sk]</td>":
echo "</tr>":
}
echo "</table>":
?>
, , :
Column Type
Null Key
id
family
name
age
N0
N0
N0
N0
smal1in t(6)
varchar(32)
varchar(32)
tinyint(4)
PRI
,
. 10.11 .
, ,
cats
, 10.9.
10.11. cats
<?php
requi re_once '1ogin.php';
$db_server = mysql_connect(Sdb_hostname. $db_username, $db_password):
270
10. MySQL
Sresult = mysql_query($query):
i f ( ! Sresult) die (" : " . mysql_error()):
?>
, ,
10.12.
10.12. cats
<?php
require_once 'login.php':
$db_server = mysql_connect($db_hostname. $db_username. $db_password):
i f ( !$db_server) die(" MySQL: " . mysql_error()):
mysql_select_db($db_database)
or die("Heooo : " . mysql_error()):
Squery = "INSERT INTO cats VALUES(NULL, 'Lion', 'Leo'. 4)";
Sresult = mysql_query(Squery);
i f ( ! Sresult) die (" : " . mysql_error());
?>
Squery, ,
:
Squery = "INSERT INTO cats VALUESCNULL. 'Cougar'. 'Growler', 2)":
Squery = "INSERT INTO cats VALUESCNULL, 'Cheetah'. Charly'. 3)":
, ,
NULL? , i d AUTO_INCREMENT MySQL ,
, NULL,
.
*
4
1 4*
, MySQL .
, cats , 10.13
, ,
.
MySQL
271
10.13. cats
<?php
require_once 'login.php';
$db_server = mysql_connect(Sdb_hostname, $db_username. $db_password);
i f ( !$db_server) die(" MySQL: " . mysql_error());
mysql_select_db($db_database)
or die(" : '' . mysql_error()):
$query = "SELECT * FROM cats":
$result = mysql_query(Squery);
i f (!$result) die (" : " . mysql_error()):
Srows = mysql_num_rows(Sresult):
echo "<table><tr> <th>Id</th> <th>Family</th>
<th>Name</th><th>Age</th></tr>";
for (Sj = 0 ; Sj < Srows : ++$j)
{
$row = m ysql_fetch_row ($result);
echo "<tr> ;
?>
M ySQL- SELECT * FROMcats,
. :
Id Family
Name
Age
1 Lion
Leo
4
2 Cougar Growler 2
3 Cheetah Charly 3
, i d
.
.
, (cheetah) Charly?
Chari i , 10.14.
10.14. Charly Charlie
<?php
requi re_once '1ogi n .php':
$db_server = mysql_connect($db_hostname. $db_usernaine. $db_password);
i f ( !$db_server) die("HeB03M0WH0 MySQL: " . m ysql_error());
mysql_select_db($db_database)
272
10. MySQL
Sresult = mysql_query($query);
i f ( ! Sresult) die (" : " . mysql_error());
?>
10.13,
:
Id Family
Name
Age
1 Lion
Leo
4
2 Cougar Growler 2
3 Cheetah Charlie 3
Growler ,
0 .
10.15.
10.15. Growler cats
<?php
require_once 'login.php :
Sdb_server = mysql_connect($db_hostname. $db_username, Sdb_password):
i f ( !$db_server) die(" MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Heooo : " . mysql_error()):
Squery = "DELETE FROM cats WHERE name='G r o w le r ;
Sresult = mysql_query($query):
i f ( ! Sresult) die (" : " . mysql_error()):
?>
DELETE FROM,
10.13, ,
:
Id Family
Name
Age
1 Lion
Leo
4
3 Cheetah Charlie 3
AUTO_INCREMENT
AUT0_INCREMENT ,
, .
, M ySQL
mysql in se rtjd . ,
Customers ,
273
MySQL
Cust Id .
10.12 10.16,
.
10.16. cats id
<?php
requi re_once 1ogin.php