Title: gDI Camp PHP
1gDI CampPHP MySQL
???????? ???????? songrit_at_gmail.com 08-9182-5567
2????? Web Services ???????????????????????????????
??????????? ???????? 1
3??????????????????????
- ??????????????????????????????????????????????????
??????????? - ???????????????????????????????
- ????????????? ???????????????????????? 10 ??
??????????????????????????????????????????????????
4??????????????????????????
- ??????????????????????????????????????????????????
???????????????? - ???????????????????? Web Services
????????????????????
5???????
- ???????????????? Web Services ????????
????????????? - ????????????????????? (REST, SOAP)
- ????????????????????????? (Open Source ????
Commercial) - ????????????????????????????????? ?????????????
- ??????????????
- ???????????????????????????
- ?????????????????????? ROI
- ??????????????????????????????????????
6????????
- ??????????? ?????????????????? 31 ??????? ??.
2549 - ???????????????? 1 ??????????????????????? 31
?????? ??. 2550 - ?????????????????????????????? (?? Source Code
????????????????????????????????) ?????????? ??.
2550 - ???????????????????????? 2 ?????? ?????????? ??.
2550
7??????
- ????????? 1 ??????????? 50,000 ???
- ????????? 2 ??????????? 30,000 ???
- ????????? 3 ??????????? 20,000 ???
8Web Architecture
Internet
Apache
PHP
MySQL
Data
pages
9Lab 1 Installation
- http//www.appservnetwork.com/
10HTML
- lthtmlgt
- ltheadgt
- lttitlegt My name is Songrit lt/titlegt
- lt/headgt
- ltbodygt
- Hello, Class
- lt/bodygt
- lt/htmlgt
11Tags
- Link Tags
- lta hrefhttp//www.cnn.com/gtCNN lt/agt
- Image Tags
- ltimg srchttp//www.x-rates.com/d/THB/USD/graph12
0.pnggtExchange Ratelt/imggt - Markup tags
- ltbgtThis text will be boldlt/bgt, ltigtitaliclt/igt,
- and this is ltugtunderlinedlt/ugt
12More tags
- Heading tags
- ltH1gtHead 1lt/H1gt
- ltH2gtHead 2lt/H2gt
- Paragraph tags
- ltpgtThis is paragraph
- ltpgtAnd this is another paragraph
- Line Break tags
- ltbrgtThis is paragraph
- ltbrgtAnd this is another paragraph
13HTML Editor
14Lab 2 Your HTML
- gdi.thaismall.com
- A, IMG, B, I, P
- http//gdi.thaismall.com/submit.php
15List
- ltulgt
- ltligtFile
- ltulgt
- ltligtNewlt/ligt
- ltligtOpenlt/ligt
- lt/ulgtlt/ligt
- ltligtEdit
- lt/ulgt
16Lab
- lthtmlgt
- ltheadgt
- lttitlegtMenult/titlegt
- lt/headgt
- ltbodygt
- lth1gtMy Menult/h1gt
- lthr /gt
- ltulgt
- ltligtFile
- ltulgt
- ltligtNew
- ltulgt
- ltligtHTMLlt/ligt
- ltligtCSSlt/ligt
- lt/ulgtlt/ligt
- ltligtOpenlt/ligt
- lt/ulgtlt/ligt
- ltligtEdit
- ltulgt
- ltligtCutlt/ligt
- ltligtCopylt/ligt
- lt/ulgtlt/ligt
- ltligtViewlt/ligt
- lt/ulgt
- lthr /gt
- lt/bodygt
- lt/htmlgt
17HTML DOM
18 19Lab CSS
- ltheadgt
- lttitlegtMenult/titlegt
- ltlink rel"stylesheet" type"text/css"
media"all" hreftree/tree.css" /gt - ltscript type"text/javascript" srctree/tree.js"gt
lt/scriptgt - lt/headgt
-
-
-
- ltul class'tree'gt
20Forms
- Text Fields.
- Password Fields.
- Text Area.
- Selectable lists.
- Radio buttons.
- Checkboxes.
- File Fields
- Hidden Field
- Submit and Reset buttons.
21Form Sample
- ltHTMLgt
- ltBODYgt ltFORM ACTIONaa.php" METHOD"post" gt
User NameltINPUT TYPE"text" NAME "uname"
SIZE30gt ltBRgt Service TypeltSELECT
NAME"service"gt - ltOPTIONgtCASltOPTIONgtCDRS ltOPTIONgtCOPSATltOPTIONgtDD
SltOPTIONgtFDSSlt/SELECTgt ltBRgt ltH4gtSUBJECT
AREAlt/H4gt ltINPUT TYPE"checkbox"
NAME"agriculture"gtAgriculture ltINPUT
TYPE"checkbox" NAME"biology"gtBiology ltINPUT
TYPE"checkbox" NAME"biomedicine"gtBiomedicine
ltINPUT TYPE"checkbox" NAME"chemistry"gtChemistry
- ltINPUT TYPEsubmit/gt
- lt/formgt
- lt/BODYgt
- lt/HTMLgt
22Lab 3 Form Page
- Create Page that has Form
23MSE to edit XML
24Lab 4 Charts
- http//www.maani.us/xml_charts/index.php
25Lab 4 Charts HTML 1
ltHTMLgt ltheadgt lttitlegtXML/SWF Chartslt/titlegt lt/head
gt ltBODYgt ltOBJECT classid"clsidD27CDB6E-AE6D-11c
f-96B8-444553540000" codebase"http//download.ma
cromedia.com/pub/shockwave/cabs/flash/swflash.cab
version6,0,0,0" WIDTH"400" HEIGHT"320"
id"charts" ALIGN""gt ltPARAM NAMEmovie
VALUE"charts.swf?library_pathcharts_libraryxml_
sourcedata.xml"gt ltPARAM NAMEquality
VALUEhighgt ltPARAM NAMEbgcolor VALUE6666aagt
26Lab 4 Charts HTML 2
- ltEMBED src"charts.swf?library_pathcharts_library
xml_sourcedata.xml" - qualityhigh
- bgcolor6666aa
- WIDTH"400"
- HEIGHT"320"
- NAME"charts"
- ALIGN""
- TYPE"application/x-shockwave-flash"
- PLUGINSPAGE"http//www.macromedia.com/go/g
etflashplayer"gt - lt/EMBEDgt
- lt/OBJECTgt
- lt/BODYgt
- lt/HTMLgt
27Lab 4 Chart XML 1
- ltchartgt
- ltchart_typegtcolumnlt/chart_typegt
- ltchart_datagt
- ltrowgt
- ltnull/gt
- ltstringgt2001lt/stringgt
- ltstringgt2002lt/stringgt
- ltstringgt2003lt/stringgt
- ltstringgt2004lt/stringgt
- lt/rowgt
- ltrowgt
- ltstringgt?????? ?lt/stringgt
- ltnumbergt5lt/numbergt
- ltnumbergt10lt/numbergt
- ltnumbergt30lt/numbergt
- ltnumbergt63lt/numbergt
- lt/rowgt
28Lab 4 Chart XML 2
- ltrowgt
- ltstringgt?????? ?lt/stringgt
- ltnumbergt100lt/numbergt
- ltnumbergt20lt/numbergt
- ltnumbergt65lt/numbergt
- ltnumbergt55lt/numbergt
- lt/rowgt
- ltrowgt
- ltstringgt?????? ?lt/stringgt
- ltnumbergt56lt/numbergt
- ltnumbergt21lt/numbergt
- ltnumbergt5lt/numbergt
- ltnumbergt90lt/numbergt
- lt/rowgt
- lt/chart_datagt
- ltlegend_label font'CordiaUPC' size'18'/gt
- lt/chartgt
29Lab 4 chart_type
- line
- bar
- area
- stacked 3d column
- parallel 3d column
- 3d pie
- polar
30PHP
- Platform Independent
- Windows
- Linux
- Mac
- Sun
- Web Server Independent
- Support All Major Databases
- Free and Open Source
31The PHP Model
ltHTMLgtlt?PHP echo(Hello World!)?gtlt/HTMLgt Bec
omes ltHTMLgtHello World!lt/HTMLgt
32Lab5.php
- lthtmlgt
- ltbodygt
- ltstronggtHello World!lt/stronggtltbr /gt
- lt?
- echo Today is
- echo date(Hi jS F)
- ?gt
- lt/bodygt
- lt/htmlgt
33Window Explorer
- Tools gt Folder Options
- View gt uncheck Hide extension for known file
types
34PHP Example 2a
- ltform actionnext.php" methodget"gt
- ltinput type"submit" name"submit"
value"Submit"gt - ltinput type"submit" name"cancel"
value"Cancel"gt - lt/formgt
35PHP Example 2b
- lt?php
- if (_GET"submit")
- echo "lth2gtYou clicked Submit!lt/h2gt"
- else if (_GET"cancel")
- echo "lth2gtYou clicked Cancel!lt/h2gt"
- ?gt
36PHP Example 3
- ltform actionnext.php" methodpost"gt
- ltinput type"submit" name"submit"
value"Submit"gt - ltinput type"submit" name"cancel"
value"Cancel"gt - lt/formgt
37Variable
- foo bar Data Type String
- foo 1 Data Type integer
- foo 5.34 Data Type Double
- foo array(bar,united) Data Type Array
38Form Variables
HTML
PHP
- ltFORM actionaa.phpgt
- Var1 ltINPUT NAMEvar1 TYPEtextgt
- Var2 ltINPUT NAMEvar2 TYPEtextgt
- lt/FORMgt
39Operators
- Assignment (e.g. , , )
- a a1 gt a 1
- Arithmetic (e.g. , -, )
- Comparison (e.g. lt, gt, gt, )
- Logical (e.g. !, , )
40If
- if (foo 0)
- echo The variable foo is equal to 0
-
- else if ((foo gt 0) (foo lt 5))
- echo The variable foo is between 1 and 5
-
- else
- echo The variable foo is equal to .foo
41Indexed Array
- marks array (95, 93, 56, 70, 65, 98)
- marks0 95
- marks1 93
- marks2 56
- marks3 70
- marks4 65
- marks5 98
42Associative Array
- marks array ("Adrian"gt93, "Lance"gt56,
"Stephen"gt70, "Craig"gt65, "Andy"gt98)
43Lab Associative Array
- lt?
- marks array ("Adrian"gt93, "Lance"gt56,
"Stephen"gt70, "Craig"gt65, "Andy"gt98) - reset(marks) // go to the beginning of the
array - echo lttable border1gt
- while (list(key, value) each(marks))
-
- echo "lttrgtlttdgtkeylt/tdgtlttdgtvaluelt/tdgtlt/trgt\n"
-
- echo "lt/tablegtlthrgt"
- ?gt
44Control Flow
- if (expr1)
- elseif (expr2)
- else
- while (cond)
- do while (cond)
- switch (var)
- case a
- case b
- for (i 0 i lt expr i )
- foreach (array_expr as value)
- foreach (array_expr as keygtvalue)
- break
- continue
45Function
- lt?
- function add (a1, a2)
- return a1a2
-
- echo add(2,2)
- ?gt
46File_get_contents
- lt?
- localfile file_get_contents("abc.txt")
- httpfile file_get_contents("http//www.cnn.com"
) - ftpfile file_get_contents("ftp//userpass_at_ftp.
example.com/abc.txt") - ?gt
47Lab 5
- File_get_contents(http//news.sanook.com/lotto/lo
tto_43824.php)
48Lab 7 make XML
- lt?xml version1.0?gt
- ltLottery roundMmm dd, yyyygt
- ltFirstPrizegtmmmmmmlt/FirstPrizegt
- ltThreeDigitgtmmmlt/ThreeDigitgt
- ltThreeDigitgtmmmlt/ThreeDigitgt
- ltThreeDigitgtmmmlt/ThreeDigitgt
- ltThreeDigitgtmmmlt/ThreeDigitgt
- ltTwoDigitgtmmmlt/TwoDigitgt
- lt/Lotterygt
49Lab 8
- Print 4 three digits winning using simplexml
50Lab Solution
- lt?
- http file_get_contents(http//localhost/lottery
.php') - xml simplexml_load_string(http)
- for (i0 ilt4 i)
- echo "ltpgtThree Digit i ".xml-gtThreeDigiti
- ?gt
51Lab 9 Geocoder
- http//brainoff.com/geocoder/rest/
- http//brainoff.com/geocoder/rest/?cityBangkok,TH
- http//brainoff.com/geocoder/rest/?cityNonthaburi
,TH - http//brainoff.com/geocoder/rest/?cityChiengmai,
TH
52Test 1
- http//192.168.0.xxx3006/test
53MySQL
- CREATE TABLE books ( idNumber int primary key
auto_increment, title varchar(30), author
varchar(30))
54MySQL
- INSERT INTO books (title,author) VALUES( Let
Freedom Ring, Sean Hannity)
55Other Operations
- ALTER TABLE books ADD COLUMN subtitle varchar(50)
AFTER title - UPDATE books SET subtitleWinning the War of
Liberty over Liberalism WHERE idNumber1 - SELECT FROM books
- DELETE FROM books
56- lt?
- db mysql_connect("localhost","root","")
- result mysql_select_db("gdi2", db)
- result mysql_query("INSERT INTO
members(fname,lname,email) VALUES('fff', 'ddd',
'eee')", db) - ?gt
57Use MySQL in PHP (1)
- lt?
- db mysql_connect("localhost",user",password
") - or die(Couldn't connect to database.")
- result mysql_select_db(dbname", db)
- or die(Couldn't select database.")
- sql SELECT username, email FROM contact
- result mysql_query(sql, db)
- or die(Something is wrong with your SQL
statement.")
58Use MySQL in PHP (2)
- while (rowmysql_fetch_array(result))
- username rowusername
- email rowemail
- echo lta href mailto.email.gt.username.lt
/agtltbr /gt\n -
- ?gt
59PHPMySQLHTML
- lt?php
- dbLink mysql_connect("localhost", dbUser,
- dbPass)
- sql "SELECT FROM books"
- res mysql_db_query("test", sql, dbLink)
- row mysql_fetch_assoc(res)
- title row"title"
- subtitle row"subtitle"
- author row"author"
- ?gt
- lttable border"1"gtlttrgt
- lttdgtltbgtTitlelt/bgtlt/tdgtlttdgtltbgtSub
Titlelt/bgtlt/tdgtlttdgtltbgtAuthorlt/bgtlt/tdgtlt/trgt - lttrgtlt?php echo "lttdgttitlelt/tdgtlttdgtsubtitlelt/tdgtlt
tdgtauthorlt/tdgt"?gt - lt/trgtlt/tablegt
60Lab 10 PhpMyAdmin
- Create table members
- id (autoincrement)
- fname
- lname
- email
- Export table
61Download
- http//192.168.0.xxx3006/download/index.html
- SQLYog
62Lab 11 PHP App
- Member Registration
- register.php
- edit.php
- thankyou.php
- list.php
63Lab 12 Search
- search.php?usernamexxx
- return HTML Table
- return XML
- lt?xml version"1.0" encoding"UTF-8" ?gt
64Lab 13 Province
- Use PhpMyAdmin to inspect province db
- province.php?idxx
- region.php?idxx
- Output as XML
65Template
http//www.tinybutstrong.com/
66lab1list.php
- lt?
- include_once('tbs.php')
- include('db.inc')
- TBS new clsTinyButStrong
- TBS-gtLoadTemplate('lab1list.tbs')
- sql'SELECT FROM lab1'
- TBS-gtMergeBlock('n',db,sql)
- TBS-gtShow()
- ?gt
67lab1list.tbs
- lttable aligncentergt
- lttrgtltthgtnamelt/thgtltthgtHTMLlt/thgtlt/trgt
- lttrgtlttd aligncentergt
- n.unamehtmlconvnoblocktr
- lt/tdgtlttdgtlta href'lab1/n.html'gt
- n.htmllt/agtlt/tdgtlt/trgt
- lt/tablegt
68Lab 14 using TBS
- province.php?idxx
- region.php?idxx
- Output as XML
69- Japan in 1993
- OOP
- Combines
- Smalltalk
- Python
- Perl
- General Public License
70- Open source Ruby framework
- Faster development
- Fewer bugs
- Convention over configuration
71Download
- http//192.168.0.xxx3006/download/index.html
- InstantRails
72win-R gt cmd
- rails gdi
- cd gdi
- ruby script\server
- http//localhost3000
73Directory Structure
- app
- model
- view
- controller
- config
- public
- images
- stylesheets
74main
- ruby script\generate controller main
- def index
- render text gt "Hello, World"
- end
75Lab 11 Revisit
- Member Registration
- register
- Username
- Full name
- Email
- update
- thankyou
- list
76Model
- ruby script\generate model Member
- scaffold