CH07 PHP - PowerPoint PPT Presentation

1 / 65
About This Presentation
Title:

CH07 PHP

Description:

CH07 PHP&MySQL Apache php Mysql Apache Apache IIS(Internet Information Services) Apache ... – PowerPoint PPT presentation

Number of Views:121
Avg rating:3.0/5.0
Slides: 66
Provided by: yang67
Category:
Tags: php | ch07 | mysql

less

Transcript and Presenter's Notes

Title: CH07 PHP


1
CH07 PHPMySQL
2
??Apache?php?Mysql??
3
Apache??
  • Apache???????,???????????IIS(Internet Information
    Services)
  • Apache????
  • ???(Linux?Windows?MAC OS X?)
  • ????????
  • ????(??????????)

4
Php??
  • PHP????????????,????????????,?????HTML??PHP???????
    ???,????????????????????,????,???PHP??
  • ????PHP???
  • (1)??????????
  • (2)?????????
  • (3)????,??????????????????Java?COM?XML?
  • (4)???(?????Web???)
  • (5)?????
  • (6)?????????????

5
PHP?Client Script(?VBscript)???
  • ????Script
  • ??????????,??????????????????????,?Javascript?VBsc
    ript?
  • ????Script
  • ??????????,???????,?????HTML,?????????????,???????
    ,?PHP?JSP?

6
Mysql
  • MySQL??????????,??MySQL AB????????????,????C?C?J
    ava?Perl?PHP??,????????????,?Linux?Windows?Sun
    Solaris ... ?,??????ODBC?????????
  • ???????MySQL?????,??????????,????????????????????,
    ???????

7
??APPSEV??
8
AppServ
  • AppServ????Apache?PHP?Mysql???????
  • ??????

9
STEP 1
10
STEP 2
11
STEP 3
12
STEP 4
??usernameroot?password(??)
13
STEP 5
14
??PHP????
15
???PHP??HTML
??
lthtmlgt ltheadgt lttitlegtHellolt/titlegt lt/headgt ltbodygt
lth1gtPHP/MySQL??lt/h1gt lt?php echo "???? PHP
Script" ?gt lt/bodygt lt/htmlgt
PHP????
??Web Server ???????PHP???,??????,??? .php? .phtml
16
PHP??
??
  • PHP???????????PHP????PHP???????
  • PHP??????????
  • ????????PHP???,???

lt?php echo "This is a PHP Scriptltbrgt" echo "The
Best Choice!" ?gt
lt?php echo date("Y-m-d") ?gt
????
17
PHP??
  • ??????????????,????????????,PHP????????????,PHP??C
    ,C?????
  • (1)C???
  • /
  • ??????
  • /
  • (2)C???
  • // ??????
  • (3)Shell Script ??
  • ??????

18
PHP??
  • ????

?? ??
(int) or (integer) ??
(real) or (double) or (float) ???
(string) ??
(array) ??
(object) ??
19
PHP??
  • ???????  . ????? ?total?vote_count  .
    ?????? ?total?Total?????????   .
    ???????????? ?2a -gt??  . ?????????????,????
    ?substr?array? . ????,??????,?????????
  • ????????

20
PHP??(????)
??
  • ????

??????????,???????? .
name "???" //?????? echo "?????ltbrgt"
echo "?????" .name a1 56 //?????? a2
42 //?????? a3 a1a2 //?????? echo
"ltbrgt ????nbspnbsp???" .a3
????
21
????
?? ?? ??
???????????????????? a5
a a 5 a5
- a a - 5 a-5
a a 5 a5
/ a a / 5 a/5
22
P7-1
  • ????????,?????????

23
PHP??(????)
??
  • ????

lt?php   your_ip "??IP?" . _SERVER'REMOTE_ADDR
' . "ltbrgt"  your_browser  "??????" . _SERVER
'HTTP_USER_AGENT' ."ltbrgt"  run_script  "????
?????" . _SERVER'PHP_SELF' . "ltbrgt"
 echo your_ip  echo your_browser
 echo run_script ?gt
24
PHP??(????)
  • ?????????
  • _GET????
  • ?????GET??????????
  • _POST????
  • ?????POST??????????
  • ????????_FILES

?????
???????????
MIME????????
25
PHP ???
  • ?????????????,????echo(PHP?????)?
    print(??)????,??echo??print????

26
??HTML??
  • ????
  • ltFORMgt...lt/FORMgt ??
  • ????
  • ACCEPT-CHARSET...???????
  • ACTIONURL??????????????
  • ENCTYPE...???MIME(???Internet????)
  • METHOD"GET,POST
  • NAME"..."
  • TARGET"..."
  • .

27
?? HTML??
  • ???????
  • ltINPUTgt ??
  • ????
  • TYPE"TEXT,PASSWORD,RADIO,CHECKBOX,
    SUBMIT,RESET,FILE,IMAGE,HIDDEN,BUTTON"
  • ??????????????,?????TYPE??????????????

28
?? HTML??
  • ?????-????
  • ???????TYPE"TEXT,???????

29
?? HTML??
  • ?????-????
  • ltinput typeSubmit value??????"gt
  • ?????-??????
  • ltinput typeReset value??????"gt

30
?? HTML??????
??
  • ?????????(test05.php)

lthtmlgt ltheadgt lttitlegtPHP????lt/titlegt lt/headgt ltFORM
METHODPOST ACTION"test06_1.php"gt ? ltINPUT
TYPE"text" NAME"h"gtltBRgt ? ltINPUT TYPE"text"
NAME"w"gtltBRgt ltINPUT TYPE"submit"
value"??"gt lt/FORMgt ltbodygt lt/bodygt lt/htmlgt
31
?????????(????????)
lthtmlgt ltheadgt lttitlegtUntitled Documentlt/titlegt ltme
ta http-equiv"Content-Type" content"text/html
charsetbig5"gt lt/headgt ltbodygt lt?php w
_POSTw h _POSTh area wh para
2 (_POSTw _POSTh) echo
ltltlttableprint lttable width"193"gt lttrgt lttd
width"52"gt?lt/tdgt lttd width"99"gt_POSThlt/tdgt lt
/trgt lttrgt lttdgt?lt/tdgt lttdgt_POSTwlt/tdgt lt/trgt ltt
rgt lttdgt??lt/tdgt lttdgtarealt/tdgt lt/trgt lttrgt lttdgt??
lt/tdgt lttdgtparalt/tdgt lt/trgt lt/tablegt tableprint ?
gt lt/bodygt lt/htmlgt
Test06_1.php
32
??
  • ???PHP??, ?????, ????, ????????? (??)

33
????
  • ??
  • UPLOAD.HTML
  • UPLOAD.PHP

34
??MySQL??
35
MySQL
  • MySQL???????????????SQL????????SQL(???????)???????
    ????????????
  • MySQL???????/????????,?????????????mysqld?????????
    ??????

36
MySQL??
  • ????????????????????????????CPU(???)?
  • C ?C? Eiffel ? Java? Perl? PHP?Python?? TCL  API
    ??20 MySQL ????? API?
  • ??????????,?Linux?Windows?MacOS ?
  • ?????????????????,???????????????????,????????????
    ,??????????
  • ??????16???????????116?????????????????? 256 ?byt
    e(???MySQL?,?????)???????????CHAR?VARCHAR??????
  • ??????????????SQL????????????????,????????????????
    ????

37
MySQL????
  • MySQL??????
  • ????
  • ???????
  • ????

38
MySQL????-????
??? ??????
TINYINT 1 byte
SMALLINT 2 ?byte
MEDIUMINT 3 ?byte
INT 4 ?byte
INTEGER 4 ?byte
BIGINT 8 ?byte
FLOAT(X) 4 ?? X lt 24 ? 8 ?? 25 lt X lt 53
FLOAT 4 ?byte
DOUBLE 8 ?byte
DOUBLE PRECISION 8 ?byte
REAL 8 ?byte
DECIMAL(M,D) Mbyte(D2 , ??M lt D)
NUMERIC(M,D) Mbyte(D2 , ??M lt D)
39
MySQL????-???????
??? ??????
DATE 3 ?byte
DATETIME 8 ?byte
TIMESTAMP 4 ?byte
TIME 3 ?byte
YEAR 1 byte
40
MySQL????-????
??? ??????
CHAR(M) Mbyte,1 lt M lt 255
VARCHAR(M) L1 byte, ??L lt M?1 lt M lt 255 (????,????????????1)
TINYBLOB, TINYTEXT L1 byte, ??Llt 2 8
BLOB, TEXT L2 byte, ??Llt 2 16
MEDIUMBLOB, MEDIUMTEXT L3 byte, ??Llt 2 24
LONGBLOB, LONGTEXT L4 byte, ??Llt 2 32
ENUM('value1','value2',...) 1 ? 2 ?byte, ?????????(???65535)
SET('value1','value2',...) 1,2,3,4?8?byte, ??????????(??64???)
41
??MySQL?????
42
MySQL?????
  • C\AppServ\MySQL??????

Mysql???????????
Mysql????????
43
Mysql?????
44
??mysql.exe??MySQL????
??MySQL???????
?????lin_DB ?slq??
??MySQL
45
???????
46
??mysql.exe??MySQL
  • Step 1 ??????-???????
  • Step 2???????,????
  • cd\appserv\mysql
  • Step 3??mysql???,????
  • mysql u root p
  • enter passwordtest
  • Step 4??mysql????,??sql?????????????????

-U?????????? ? p ?????????
??
47
??MySQL??????
  • ?????board
  • Create database board
  • ?????message

??board???
?????message?????
48
MySQL???????sql????
a.sql???c\appserv\mysql????
49
MySQL???????sql????
50
MYSQL???????
?? ??
tbl_name.frm ???(??)??
tbl_name.MYD ????
tbl_name.MYI ????
51
???phpMyAdmin ?? ??MySQLy ???
52
phpMyAdmin??(?)
  • ??phpMyAdmin?????C\AppServ\www\phpMyAdmin
  • ????(??????,?????)
  • ???????(wordpad)????? config.inc.php??
  • ....(?) If the auto-detection code does work
    properly, you can set to TRUE the
    cfg'PmaAbsoluteUri_DisableWarning' variable
    below./cfg'PmaAbsoluteUri'
    'http//192.168.0.xxx/phpMyAdmin/' (??
    phpMyAdmin ?????)

53
phpMyAdmin??(?)
  • ????phpMyAdmin????
  • 1. ??IE
  • 2. ???http//localhost/phpMyadmin/main.php
  • 3. ??????
  • ???????phpmyadmin.doc????

54
phpMyAdmin??(?)
???????
55
??PHP MYSQL
56
PHP??mysql??????
  • ?????
  • ?????
  • ??SQL???? or ????
  • ?????? ????????? SELECT???
  • ???????

57
?????
  • ????mysql_connect("Mysql????", "??", "??")
  • ???????,????? MySQL link ?????,??????? FALSE
  • EX.
  • //?root??MySQL???
  • host"localhost"
  • user"root"
  • ps"test"
  • link mysql_connect(host,user,ps)

58
?????
  • ?????mysql_select_db("?????")
  • ??????,??? True ?,???? False ??
  • Ex.
  • //??board??????
  • dbase"board"
  • mysql_select_db(dbase,link)

????????
59
??SQL??
  • ??SQL??(??) query "SELECT FROM my_table"
    (??) query "INSERT INTO my_table (c1,c2,...)
    VALUES ( value1,value2, ...)"(??) query
    "UPDATE my_table SET c1'abc' WHERE id'100'
    "(??) query "DELETE FROM my_table WHERE
    id'100' "
  • ??SQL????????result mysql_query(query)

60
??SQL??
  • EX1.??????
  • //??SQL??,?????board???,????????
  • insert_str "Insert into message(name,content,
    time)
  • Values('uname','content',Now())"
  • mysql_query(insert_str,link)
  • EX2.????
  • //??????
  • //????????????????,????????
  • select_str"Select From message Order by no
    DESC"
  • resultmysql_query(select_str,link)

61
?????
  • //???????
  • mysql_close(link)

62
?????
63
?????
64
lt?php //??MySQL???? host"localhost" user"roo
t" ps"test" dbase"board" //???????????????
uname"" content"" //????????
if(isset(_POST"uname")) uname
_POST"uname" if(isset(_POST"content"))
content _POST"content"
//???????????????? if(!empty(uname)
!empty(content)) //?root??MySQL??? link
mysql_connect(host,user,ps)
//??board?????? mysql_select_db(dbase,link)
//???????,nl2b()???????????ltbrgt
//addslashes()?????????? \ contentaddslashes
(nl2br(content)) //??SQL??,?????board???,??
?????? insert_str "Insert into
message(name,content,time) Values('uname','con
tent',Now())" mysql_query(insert_str,link)
//??????? mysql_close(link) ?gt
mysql ???????
65
lt?php host"localhost" user"root" ps"test"
dbase"board" //?board????,??????????????????
//?linda??MySQL??? link mysql_connect(host,
user,ps) //??surpro?????? mysql_select_db(db
ase,link) //?????? //????????????????,???????
? select_str"Select From message Order by
no DESC" resultmysql_query(select_str,link)
//?????????? rowsmysql_num_rows(result)
//????????? for(x0xltrowsx)
//??????????????? arrdataxmysql_fetch_array
(result,MYSQL_ASSOC) //???? echo
arrdatax'time'."--gtgt" echo
arrdatax'name'." ????ltpgt" echo
arrdatax'content'."lthrgt" //????
mysql_close(link) ?gt
mysql ???????
Write a Comment
User Comments (0)
About PowerShow.com