????????????????????????????? ??????????????? PHP - PowerPoint PPT Presentation

1 / 137
About This Presentation
Title:

????????????????????????????? ??????????????? PHP

Description:

php ... – PowerPoint PPT presentation

Number of Views:227
Avg rating:3.0/5.0
Slides: 138
Provided by: esanclub
Category:
Tags: php

less

Transcript and Presenter's Notes

Title: ????????????????????????????? ??????????????? PHP


1
???????????????????????????????????????????? PHP
  • ????? ????????

2
???????????????
  • ??????????????????????????????????? PHP
  • ?????????????????? PHP ?????????????????? MYSQL
    ???
  • ??????????????????????????????????????????????
  • ??????????????????????????????????????????????????
    ??????? Web Application

3
????????????
  • ?????? 12 ?????????? 2550
  • ?????????????? , ?????????? AppServ, ??????????
    Eclipse
  • ?????? 13 ?????????? 2550
  • ???????????????????????? ?
  • ?????? 14 ?????????? 2550
  • ???????? Web Form, ?????????????????, phpMyadmin
  • ?????? 15 ?????????? 2550
  • ???????????????????? ITIL
  • ?????? 16 ?????????? 2550
  • ???????????????????? ITIL

4
Download ??????????????????????
  • ????? Folder ???? c\php_train
  • ftp//ftp.nso.go.th/public/Training/PHP_2550
  • ???????????????? Tools ???????????????????? Save
    Target As ?????? c\php_train
  • ???????????????? PHP ???????????????????? Save
    Target As ?????? c\php_train

5
  • ??????????????

6
?????????????????????????????
  • ??????????????????? ?????????? (Algorithm)
    ?????????????????? (Data Structure)
  • ???????????????????????????????????? (Software
    Engineering)
  • ??????????????????? HTML, XHTML, CSS, DOM,
    JavaScript, XML
  • ??????????????????????????????????????????? ????
    Application Server , Framework, Programming
  • ?????????????????????????????????????????
    (Programming Language)
  • ??????????????????????????????????????????????????
    ???? (Web Application Security)

7
Web Application Model
8
Web Application Deployment
  • App Server
  • Apache Web Server
  • PHP
  • Browser Client
  • HTML,CSS,XML
  • DOM
  • Java Script
  • Java Applete
  • Database Server
  • MYSQL

9
?????????????? 3-Tier
10
??????????????????? MVC
11
MVC Model
  • VIEW
  • ???????????????????? ???? images, CSS,JS,XX.php
  • Control
  • Action
  • config
  • Model
  • business
  • Database
  • metadata

12
W3 Schools
13
Certificate
14
HTML Document
  • lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  • "http//www.w3.org/TR/html4/strict.dtd"gt
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtMy first HTML documentlt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • ltPgtHello world!
  • lt/BODYgt
  • lt/HTMLgt

15
What Is XHTML ?
  • XHTML stands for EXtensible HyperText Markup
    Language
  • XHTML is aimed to replace HTML
  • XHTML is almost identical to HTML 4.01
  • XHTML is a stricter and cleaner version of HTML
  • XHTML is HTML defined as an XML application
  • XHTML is a W3C Recommendation

16
XHTML
  • lt!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Strict//EN" "http//www.w3.org/TR/xhtml1/DTD/xhtml
    1-strict.dtd"gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtsimple documentlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltpgta simple paragraphlt/pgt
  • lt/bodygt
  • lt/htmlgt

17
What is xml ?
  • XML stands for EXtensible Markup Language
  • XML is a markup language much like HTML
  • XML was designed to describe data
  • XML tags are not predefined. You must define your
    own tags
  • XML uses a Document Type Definition (DTD) or an
    XML Schema to describe the data
  • XML with a DTD or XML Schema is designed to be
    self-descriptive
  • XML is a W3C Recommendation
  • http//www.w3schools.com/xml/xml_examples.asp

18
Style Sheet
  • ?????? presentation style ??? document
    ??????????????????? documents.
  • CSS simplifies Web authoring and site maintenance
    such as the text ,the backgrounds, the font size
    and style.
  • http//www.w3schools.com/css/default.asp

19
JavaScript
  • JavaScript is a scriping language designed for
    adding interactivity to HTML pages
  • JavaScript is an interpreted language .
  • ltscript language"JavaScript"gtlt!--
    document.write("This text is written using
    JavaScript!")//--gtlt/scriptgt

20
DOM (Document Object Model )
http//www.w3schools.com/htmldom/default.asp
21
Object Collection
22
Object Methods
23
Object Properties
24
SDLC
25
UML Diagram
Sequence Diagram
Class Diagram
26
UML (Unified Modelling Language )
  • Use case
  • Class Diagram
  • Object Diagram
  • Sequence Diagram
  • Collaboration Diagram
  • State Diagram
  • Deployment Diagram

27
PHP and the OWASP Top Ten Security
Vulnerabilities
  • Unvalidated Parameters
  • Broken Access Control
  • Broken Account and Session Management
  • Cross-Site Scripting (XSS) Flaws
  • Buffer Overflows
  • Command Injection Flaws
  • Error Handling Problems
  • Insecure Use of Cryptography
  • Remote Administration Flaws
  • Web and Application Server Misconfiguration

28
  • ITIL WEB
  • Application

29
ITIL Requirement Statement
  • ????????????????????????????????????????????????
    ??????????????????????????????????????????????????
    ?? ???????????????????????????????????????????????
    ???????????????????????????????
    ??????????????????????????????????????????????????
    ??????????????????????? ??????????????????????????
    ???? ????????????????????????????????
  • ????????????????????????????????????????????????
    ???????, ?????????? ??? ??????????? Support

30
Development Process
31
Tools
  • Analysis Phase
  • Capture Requirement Use case Diagram
  • Business Process Activity Diagram
  • Object Domain Class Diagram
  • Design Phase
  • Input Output Design Class Diagram, Prototype
  • Database Design E-R Diagram, Class Diagram
  • Software Structure Deployment Diagram

32
Use Case
33
Class Diagram
34
  • ??????????
  • AppServ

35
AppServ Open Project
36
AppServ v 2.5.7
37
?????????? App Server v 2.5.7
  • ??????????????????? appserv-win32-2.5.7.exe
  • ????????????? C\AppServ
  • ???????????????
  • C\AppServ\Apache2.2
  • C\AppServ\Mysql
  • C\AppServ\PHP5
  • C\AppServ\WWW
  • ??????????????? http\\localhost
  • ?????????????????????????????
  • C\AppServ\WWW

38
Security Warning
39
Welcome
40
Backup Old Data
41
License Agreement
42
Folder ??????????
43
Select Component
44
Server Information
localhost
email_at_nso.go.th
45
MySQL Server
passw0rd
tis620
46
??????????
47
?????????????????
48
??????????????????????????
49
http//localhost
50
PHP.INI
51
Uninstall
52
  • ?????????? IDE
  • eclipse 3.1

53
???????????????????? eclipse 3.1
  • jdk-1_5_0_07-windows-i586-p.exe
  • eclipse-SDK-3.1.2-win32.zip
  • dbg-2.15.1-win32-php516.zip
  • PHPEclipse1.1.3-2005-01-29.zip
  • net.sourceforge.phpeclipse_1.1.8.bin.dist.zip

54
????????????????? eclipse 3.1
  • ??????? JDK
  • extract ???? eclipse-SDK-3.1.2-win32.zip ????????
    c\eclipse
  • extract ???? net.sourceforge.phpeclipse_1.1.8.bin.
    dist.zip
  • ???????? c\eclipse
  • extract ???? PHPEclipse1.1.3-2005-01-29.zip
    ???????? c\eclipse
  • extract ???? dbg-2.15.1-win32-php516.zip
    ?????????????? php_dbg.dll ??????????????
    c\appserv\php5\ext

55
????????????????? eclipse 3.1 (???)
  • ????????? C\WINDOWS\php.ini ??????????? notepad
    ??????
  • ???????? extension
  • extensionphp_dbg.dll ????????????? extension
  • ????????????
  • debugger
  • debugger.enabled on
  • debugger.profiler_enabled on
  • debugger.JIT_host clienthost
  • debugger.JIT_port 7869
  • debugger.hosts_allow localhost 127.0.0.1
  • debugger.hosts_denyALL
  • debugger.ports7869, 10001, 10002, 10003,
    10000/16

56
????????????????? eclipse 3.1 (???)
  • ????? Stop Apache ???? Start ????
  • ????? phpinfo

57
Eclipse Concept
  • Workspace (???? .metadata)
  • Perspective (??? PHP ??? Debug)
  • View
  • Editor

58
New
  • ????? Project ????
  • File-gtNew-gtPHP Project
  • ????? PHP File ????
  • File-gtNew-gtPHP File
  • ????? HTML ????
  • File-gtNew-gtHTML File

59
New Project
60
New PHP File
61
???????? Config ????? Run/Debug Program
  • ?????????????? Project ?? Navigator View-gtRun
    As-gtRun
  • ????? PHP DBG Script
  • ????? , ??, ????? Config ???
  • ??? Tab File ????????
  • Project , File ?????????? Run
  • ????????????? Browse

62
???????? Config ????? Run/Debug Program
  • ????? Tab ???? PHP Environment ?????
  • Tab ???? Interpreter ????????? New ??????????
    c\AppServ\php5\php.exe
  • Tab ???? Remote Debug -gt ???????????? 3

63
???????? Config ????? Run/Debug Program
  • ????? Tab ????Common ???????? mark ??? Run ???
    Debug

64
  • ???????????
  • PHP

65
Rasmus Lerdorf
http//lerdorf.com/bio.php
66
PHP History Version
  • PHP/FI (Personal Home Page / Forms Interpreter)
    2538
  • PHP 2.0 (PHP/FI 2.0)
  • PHP 3.0
  • PHP 4.0 (4.4.4)
  • PHP 5.0 (5.1.6)

67
PHP Reference
  • http//www.w3schools.com/
  • http//www.php.net
  • http//www.phpfreaks.com
  • http//www.tizag.com
  • http//th2.php.net/manual/en/language.types.php

68
What is PHP ?
  • PHP is a server-side scripting language, like ASP
  • PHP scripts are executed on the server
  • PHP supports many databases (MySQL, Informix,
    Oracle, Sybase, Generic ODBC, etc.)
  • PHP is an open source software (OSS)
  • PHP is free to download and use

69
What is a PHP File?
  • PHP ?????????? HTML tags ??? PHP Tag
    (lt?php .. ?gt )
  • PHP ?????????????????? HTML 
  • PHP ????????????? .php

70
??????????? PHP Interpreter
71
PHP Example
  • lthtmlgt
  • ltheadgt
  • lttitlegtPHP Examplelt/titlegt
  • lt/headgt
  • ltbodygt
  • lt?php
  • echo "Hi, I'm a PHP script!"
  • ?gt
  • lt/bodygt
  • lt/htmlgt

72
PHP Tag Style
  • ?????? 1 SGML Style lt? ... ?gt
  • ?????? 2 XML Style lt?php ... ?gt
  • ?????? 3 JavaScript Style
  • ltscript language"php"gt
  • lt/scriptgt
  • ?????? 4 ASP or JSP Style lt gt

73
??????????????????????????????
  • ??????????????????????
  • ??????????????
  • ???????????????
  • Syntax ???
  • Logic ???

74
Coding Tips
  • Indentation and Spacing
  • ???????????????? ??? Space ???????????????????????
    ??????? ????
  • lt?php if(is_dir(directory))function() ?gt
    ???????
  • lt?phpif ( is_dir(directory) )   function
    ()
  • ?gt
  • Variable Naming ?????????
  • variable_name ???? first_name, last_name
  • Function Naming ?????????
  • VariableName ???? GetText()

75
Coding Tips (continue)
  • Magic Numbers
  • ??? if (status 3) ??????????????
  • define ('DELETED', '3')
  • if (status DELETED)
  • Single or double quotes
  • first_name ????????? first_name
  • ?????????????????????? single quote
    ??????????????????????????????????
  • Brackets
  • ?????? ?????????????????????????????????????
    ??????

76
Flowchart ??? Pseudocode
pseudocode sum 0  count 1  REPEAT   IF
count is even THEN sum sum count   count
count 1  UNTIL count gt 20  DISPLAY sum
77
  • ??????????????????

78
 ????????(Comment)
  • Single line -gt //
  • ???? // Connect To Database
  • Multiple line -gt /
  • ..
  • ..
  • /
  • Shell-Style -gt .

79
?????? (Variable)
  • ??????????????????????????????????????
  • ?????????????(Type Of Variable)
  • ??????????????? (Scope Of Variable)

80
????????????????? (Variable )
  • ?????????????????? ?????????? ???? name
  • ???????????????(letter) ???? underscore
    ????????????????????? ?????? ???? underscores. (
    it would be expressed thus a-zA-Z0-9_\x7f-\xff
    ' )
  • ?????????????????????????????????????
    (case-sensitive)
  • ???????????????????????????? ???? thai_month
  • PHP ??????????? Strong Type ????????????????
    mixedmode ????????????????????????????????????
  • Predefined variables (????????????????????????)

81
PHP supports eight primitive types.
  • Four scalar types
  • boolean
  • integer
  • float (floating-point number, aka 'double')
  • string
  • Two compound types
  • array
  • object
  • Two special types
  • resource
  • NULL
  • Four pseudo-types types
  • mixed
  • number
  • callback

82
????????????? (Type Of Variable)
  • Integer Number ???? rows200
  • Floating Point Number ???? pi3.1416
  • Boolean ???? flagtrue
  • String ???? nameSongpon Maisalee
  • Array ???? arr array(1,2)
  • Object ???? obj new

83
Boolean
  • TRUE or FALSE. Both are case-insensitive.
  • ?????????????????????????????????????????????? 0
    ???? false
  • ???????????(????)???????????????????

84
Integer Floating Point
  • ??????? integer ??????? CPU ??????????????????????
    ?? 2 billion (that's 32 bits signed)
  • ??????? floating point ??????? CPU
    ???????????????????????? 1.8e308 with a
    precision of roughly 14 decimal digits is a
    common value (that's 64 bit IEEE format).

85
Integer
  • decimal 1-90-9 0
  • hexadecimal 0xX0-9a-fA-F
  • octal 00-7
  • integer -?decimal
  • -?hexadecimal
  • -?octal
  • a 0123 // octal number (equivalent to 83
    decimal)
  • a 0x1A // hexadecimal number (equivalent to
    26 decimal)

86
Floating point
  • LNUM  0-9
  • DNUM  (0-9\.LNUM)  (LNUM\.0-9)
  • EXPONENT_DNUM 
  • ( (LNUM  DNUM) eE-? LNUM)

87
String
  • ???????????????????? single quoted, double
    quoted, heredoc
  • ???????? Array ???????????
  • ?????? 64 ????????
  • String Function
  • strlen, strpos, strstr,strchar
  • substr, strcmp, str_replace
  • trim, rtrim
  • String Conversion ????????????????

88
Object
  • ???????? class
  • class class_name Method/Function
  • _constructor() , _destruct()
  • Create Object
  • var new class_name
  • Access Variable and Method in Object
  • var-gtVarname Or Method
  • inheritance By extends
  • class Named_Cart extends Cart
  • Scope Resolution Operator ()
  • parentCONST_VAL,selfmyitem

89
Computer Object Domain
90
Array
  • ???? Dynamic Array (??????????????????)
  • ??????????? Function ???? ?????????????? ????
    var array("foo" gt "bar", 12 gt
    true)
  • Index ???????? 0 ??????????????????????? Index
    ?????
  • ?????????????????????????????????????????????(????
    ????)
  • ???????????? Dimension Array ???
  • Function ????????? Array (????? Help)
  • array, sizeof, unset

91
Array (Cont)
  • array( key gt value , ... )
  • // key may be an integer or string
  • // value may be any value
  • arrkey value arr value
  • // key may be an integer or string
  • // value may be any value

92
Constants
  • ??????????????????????????????????????????????????
    ????????????
  • ?????? define()
  • define ("MAXSIZE", 100)
  • echo MAXSIZE
  • if (defined("CONSTANT"))
  • echo CONSTANT

93
Type Casting
  • (int), (integer) - cast to integer
  • (real), (double), (float) - cast to double
  • (string) - cast to string
  • (array) - cast to array
  • (object) - cast to object

94
Variable Scope ???????????????
  • Local Scope
  • By Default
  • Global Scope
  • global a,b ???? GLOBALSx
  • Static
  • static int 0 

95
Expr Expression
  • expression is "anything that has a value".
  • Any numeric non-zero numeric value is TRUE, zero
    is FALSE, negative values are non-zero and are
    thus considered TRUE.
  • The empty string and the string "0" are FALSE
    all other strings are TRUE.
  • With non-scalar values (arrays and objects) - if
    the value contains no elements it's considered
    FALSE, otherwise it's considered TRUE.

96
Operator ????????
  • Arithmetic Operators , - , , / ,
  • Assignment Operator (var othervar
    Reference)
  • Incrementing/Decrementing Operators a, a,
    --a, a--
  • Comparison Operators ,!,lt,gtlt,gt
  • Logical Operators , , !, and, or, xor
  • String Operators . , .
  • Bitwise Operators , , ltlt, gtgt,
  • Error Control Operators _at_
  • Execution Operators ls -l
  • Operator Precedence ??????????

97
highest-precedence operators listed at the top of
the table
98
Control Structure Statement
  • if ,else, elseif
  • for,foreach
  • while, do .. while
  • switch
  • break(for,while,switch) , continute
  • require,require_once,include,include_one
  • die(), exit()

99
IF Statement
  • If (expr) statements
  • If (expr)
  • statements
  • else
  • statements
  • If (expr)
  • statements
  • elseif
  • statements
  • else
  • statements

100
For Statement
  • for (initialization condition increment)
  • statements
  • ???? for (expr1 expr2 expr3) statement
  • for (expr1 expr2 expr3)
  • statements
  • endfor
  • foreach (array as value)
  • statements

101
While Do Statement
  • while (expr)
  • statements
  • while (expr)
  • statements
  • endwhile
  • do
  • statements
  • while (expr)

102
Switch Statement
  • One Check, Support -gtString, Integer
  • switch (i)
  • case 1
  • statements
  • break
  • case 2
  • statements
  • break
  • default
  • statements
  • switch (i)
  • case 0
  • statements
  • break
  • default
  • statements
  • print "i is not equal to 0, 1 or 2"
  • endswitch

103
?????????????????? Include Require
  • include() , Include_once() ,require() ,
    require_once()
  • take a local file or URL as input
  • include() and include_once() provide a warning if
    the resource cannot be retrieved and try to
    continue execution of the program if possible
  • require() and require_once functions provide stop
    processing the page if they cannot retrieve the
    resource
  • It is best to use require_once() to include files
    which contain necessary code and include_once()
    to include files that contain content which the
    program can run without e.g. HTML, CSS, etc.

104
Custom Function
  • function fun_name(para1,para2,)
  • return xx
  • Arguments
  • Pass By Reference -gt xx
  • Pass By Value -gt xx
  • include, require,require_once

105
Built In Function
  • Mathematical Function
  • Data File Function
  • String Function
  • etc. ?????????????? Function Reference

106
Builtin Function
  • echo , var_dump, sizeof, array, unset

107
Date and Time functions
  • checkdate Validate a gregorian date/time
  • date Format a local time/date
  • getdate Get date/time information
  • gettimeofday Get current time
  • gmdate Format a GMT/CUT date/time
  • gmmktime Get UNIX timestamp for a GMT date
  • gmstrftime Format a GMT/CUT time/date according
    to locale settings
  • localtime Get the local time
  • microtime Return current UNIX timestamp with
    microseconds
  • mktime Get UNIX timestamp for a date
  • strftime Format a local time/date according to
    locale settings
  • time Return current UNIX timestamp
  • strtotime Parse about any english textual
    datetime description into a UNIX timestamp

108
Error Handling
  • PHP.INI -gt
  • error_reporting E_ALL
  • display_errors On
  • log_errors On , error_log /path/to/filename
  • set_error_handler()
  • trigger_error()
  • E_USER_NOTICE
  • E_USER_WARNING
  • E_USER_ERROR

109
  • ??????????????????

110
  • Web Form

111
Form Elements
  • FORM - Interactive form
  • BUTTON - Button
  • FIELDSET - Form control group
  • LEGEND - Fieldset caption
  • INPUT - Form input
  • LABEL - Form field label
  • SELECT - Option selector
  • OPTGROUP - Option group
  • OPTION - Menu option
  • TEXTAREA - Multi-line text input

112
FORM
  • Syntax
  • ltFORMgt...lt/FORMgt
  • Attribute
  • METHOD get post  (HTTP method for submitting
    form)
  • ENCTYPEContentType (content type to submit form
    as)
  • ACCEPT-CHARSETCharsets (supported character
    encodings)
  • TARGETFrameTarget (frame to render form result
    in)
  • ONSUBMITScript (form was submitted)
  • ONRESETScript (form was reset)

113
Get VS Post Method
  • ??? GET, ????????????????????????????? page
    address ??? POST ???????????????
  • ??? GET ???????????? form
  • ??? GET ??????????????????????????? 256 ????????
  • yourpage.php?userdavidreferrergowansnetarea6
  • variablename_POST'variable'
  • variablename_GET'variable'

114
Get Example
  • http//yourpage.php?userdavidreferrergowansnet
    area6
  • ???????????????
  • variablename_GET'variable'
  • ??? ?????????????????

115
Post Example
  • ltform namefrm1 actionurl method post gt
  • ltinput typetext name user valuedavidgt
  • ltinput typetext name referrer valuegowansnetgt
  • ltinput typetext name area value6gt
  • lt/formgt
  • ???????????????
  • variablename_POST'variable'
  • ?????????? SUBMIT

116
Import_request_variables
  • bool import_request_variables ( string types ,
    string prefix )
  • Types 'G', 'P' and 'C' characters respectively
    for GET, POST and Cookie.
  • ???? import_request_variables("gP",
    "rvar_")

117
Input Validate
  • Client Validate at Client
  • Server Validate at Server
  • Use Regular expression /\d5/
  • ,,,?,,.,,,(),

118
What is cookie ?
  • ?????????????? Text File ?????????????????
  • setcookie("totals",23)
  • HTTP_COOKIE_VARS"totals"

119
What is session ?
  • A visitor accessing your web site is assigned an
    unique id, the so-called session id.
  • PHP will check automatically (if
    session.auto_start is set to 1) or on your
    request (explicitly through session_start() or
    implicitly through session_register()) whether a
    specific session id has been sent with the
    request.
  • ?????????????? Memory ?? Sever

120
Session Handling
  • session_start Initialize session data
  • session_destroy Destroys all data registered to
    a session
  • session_name Get and/or set the current session
    name
  • session_module_name Get and/or set the current
    session module
  • session_save_path Get and/or set the current
    session save path
  • session_id Get and/or set the current session
    id
  • session_register Register one or more variables
    with the current session
  • session_unregister Unregister a variable from
    the current session
  • session_unset Free all session variables
  • session_is_registered Find out if a variable is
    registered in a session
  • session_get_cookie_params Get the session
    cookie parameters
  • session_set_cookie_params Set the session
    cookie parameters
  • session_decode Decodes session data from a
    string
  • session_encode Encodes the current session data
    as a string
  • session_set_save_handler Sets user-level
    session storage functions
  • session_cache_limiter Get and/or set the
    current cache limiter

121
  • ?????????????

122
RDBMS
  • Table
  • Record
  • Field
  • Key

123
Database Step
  • Create a database
  • Create User
  • Grant Permission
  • Create a table
  • Create Index
  • Create table constrain
  • Load data into the table
  • Retrieve data from the table in various ways
  • Backup

124
phpMyAdmin
125
???????? Password ???????
  • ??????????????????????????????? root ???????
    passw0rd ???????? ??????????????

126
??? Password ??? config.inc.php
  • ???? config.inc.php ?????????? c\AppServ\www\phpM
    yAdmin
  • ???????????? Editor ??
  • cfg'Servers'i'password' '' //
    MySQL password
  • ???????
  • cfg'Servers'i'password' passw0rd'

127
??????????????????????????????????
  • ????? Login ???? phpMyAdmin
  • MySQL connection collation ???? tis620_thai_ci
  • ??????????????????
  • ???????????????? train_db
  • ??????????????????????
  • tis620_thai_ci
  • ???????????

CREATE DATABASE train_db DEFAULT CHARACTER SET
tis620 COLLATE tis620_thai_ci
128
?????????????
  • ?????????????????? train_db
  • ???????????????? php_student ?????????????????? 4
    ???????????

CREATE TABLE train_db ( id CHAR( 2 ) NOT NULL
,thai_name VARCHAR( 100 ) NOT NULL
,position VARCHAR( 80 ) NOT NULL
,department VARCHAR( 80 ) NOT NULL ) TYPE
MYISAM
129
??????????????????????????
130
Select Statement
  • SELECT STRAIGHT_JOIN SQL_SMALL_RESULT
    SQL_BIG_RESULT
  • SQL_BUFFER_RESULT SQL_CACHE SQL_NO_CACHE
    SQL_CALC_FOUND_ROWS HIGH_PRIORITY DISTINCT
    DISTINCTROW ALL select_expression,...
  • INTO OUTFILE DUMPFILE 'file_name'
    export_options
  • FROM table_references
  • WHERE where_definition
  • GROUP BY unsigned_integer col_name
    formula ASC DESC, ...
  • HAVING where_definition
  • ORDER BY unsigned_integer col_name
    formula ASC DESC ,...
  • LIMIT offset, rows
  • PROCEDURE procedure_name
  • FOR UPDATE LOCK IN SHARE MODE
  • Example
  • SELECT what_to_select FROM which_table WHERE
    conditions_to_satisfy
  • SELECT FROM pet WHERE name "Bowser"

131
Update Statement
  • UPDATE LOW_PRIORITY IGNORE tbl_name SET
    col_name1expr1 , col_name2expr2, ... WHERE
    where_definition LIMIT
  • Example
  • UPDATE persondata SET ageage2

132
Insert Statement
  • INSERT LOW_PRIORITY DELAYED IGNORE INTO
    tbl_name (col_name,...) VALUES ((expression
    DEFAULT),...),(...),...
  • Example
  • INSERT INTO tbl_name (col1,col2)
    VALUES(col22,15)

133
Delete Statement
  • DELETE LOW_PRIORITY QUICK FROM table_name
  • WHERE where_definition ORDER BY ...
    LIMIT rows
  • Example
  • DELETE FROM table_name WHERE 1gt0

134
??????????????
  • ????? Global level
  • ??????????????????????????????????????????????
    ???????? ??? ?????????? ????????????????????
    mysql.user ???? grant all on . to
    userxx_at_localhost identified by userxx
  • ????? Database Level
  • ??????????????????????????????? ???????? ???
    ?????????? ???????????????????????????????????
    mysql.db ??? mysql.host ???? grant all on
    dbname. to userxx_at_localhost identified by
    userxx
  • ????? Table Level
  • ?????????????????????????????????????????????????
    ??? ?????????? ????????????????????mysql.tables_pr
    iv ???? grant all on .tabname to
    userxx_at_localhost identified by userxx
  • ????? Column Level
  • ??????????????????????????????????????????????????
    ???? ????????????????????mysql.tables_priv
  • ????????????
  • global privileges OR (database privileges AND
    host privileges) OR table privileges OR column
    privileges

135
Database Functions
  • int mysql_connect(host,usrer,pass)
  • int mysql_pconnect (host,usrer,pass)
  • Int myql_create_db(database_name,database_connec
    t)
  • int mysql_select_db(databasename)
  • int mysql_query(query,database_connect)
  • mysql_close(database_connect)
  • Int mysql_drop(database_name,database_connect)

136
Database Functions (continue)
  • int mysql_fetch_array(result,result_type)
  • int mysql_fetch_row(result)
  • int mysql_num_rows(result)
  • mixed mysql_result(result,row,field)
  • object mysql_fetch_object(result)

137
Database Functions
  • int mysql_connect(host,usrer,pass)
  • int mysql_query(query,database_connect)
  • int mysql_db_query(query,database_connect)
  • mysql_close(database_connect)
  • int mysql_fetch_array(result,result_type)
  • int mysql_fetch_row(result)
  • int mysql_num_rows(result)
  • mixed mysql_result(result,row,field)
  • object mysql_fetch_object(result)
Write a Comment
User Comments (0)
About PowerShow.com