PHP MySQL Basic - Training Slides.ppt

January 5, 2017 | Author: Basyiroh Saad | Category: N/A
Share Embed Donate


Short Description

Download PHP MySQL Basic - Training Slides.ppt...

Description

Introduction to PHP & MySQL

A 4 days Course Presented by

Shaizar Md Daud @ Jat

Course Outline    

       

Introduction to HTML Introduction to PHP PHP - The Language Using Variables Giving Your Code Life – Flow Control Using Functions Creating Custom Functions Making Things Constant Variable Scope – Now You See Me, Now You Don‟t! Introduction to Database & MySQL Using MySQL from PHP Putting things Together – Lab Project 9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Day 1   

Introduction to HTML Introduction to PHP PHP - The Language

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

What is HTML? 

Hyper-Text Markup Language –

– – – – – –

Language for creating web pages Defines format & layout of a document Documents are Portable Link multiple documents Local and remote documents A simple text file Tag-based language

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Markup Tags 

Single Tags –

No Content or Child Tags

Syntax: or Example:

, ,

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Markup Tags, cont’d 

Start and End Tags –

Contains Content or Child Tags

Syntax: Some Content Example:

The quick brown fox jumps over the lazy dog

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Comments 

Comments are not rendered (displayed)

Syntax: Example:

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Document Structure  

Document Type Declaration HTML Container – –

HTML Header HTML Body

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

DOCTYPE HTML Document Structure

Common DOCTYPEs:

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Container Tags HTML Document Structure Start Tag

End Tag

Description





HTML Container





HTML Header Section





HTML Body Section

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Layout Tags Start Tag

End Tag







-





9 - 12 April 2007

Description Paragraph Text Insert Line Break Division Block

Trainer: Shaizar Md Daud ([email protected])

HTML Text Formatting Tags Start Tag

End Tag





Bold Text





Bold Text





Italic Text





Underline Text



-

Horizontal Line









9 - 12 April 2007

Description

Text Headers [ n = 1 – 6 ] Apply Format Elements to Text Trainer: Shaizar Md Daud ([email protected])

HTML List Tags Start Tag

End Tag

Description





Ordered List





Unordered List





List Item

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Ordered List Tag Syntax: [ list items ]

Example: Item 1 Item 2

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Unordered List Tag Syntax: [ list items ]

Example: Item 1 Item 2

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Table Start Tag

End Tag

Description





Table Container





Table Row





Table Data

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Table Example Row 1, Column 1 Row 1, Column 2 Row 2, Column 1 Row 2, Column 2

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

HTML Tags HTML Links Start Tag

End Tag





Anchor link to a URL.





Anchor link to an Target ID.





Target ID to link to.

9 - 12 April 2007

Description

Trainer: Shaizar Md Daud ([email protected])

HTML Forms Start Tag

End Tag

Description





Form Container



-





Select Box Container





Select Box Options





9 - 12 April 2007

Input Fields

Text Box

Trainer: Shaizar Md Daud ([email protected])

Form Tag Syntax: Example: . . . . . .

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Input Tag 

Attributes –

type 

– – –

– –

TEXT | CHECKBOX | RADIO | PASSWORD | HIDDEN | SUBMIT | RESET | BUTTON

name value size maxlength checked 9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Input Tag, cont’d Example:

Male Female Yes 9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Select Tag 

Attributes – – –

name size multiple

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Option Tag   

Used within SELECT tags. Defines SELECT Items. Attributes – –



value selected

CDATA = Select item label

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

SELECT … OPTION Example: Selangor

Johor Kedah

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

SELECT … OPTION (multiple) Example: Selangor

Johor Kedah

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

TextArea Tag 

Attributes – – –



rows cols wrap: [ soft | hard | off ]

CDATA –

Text to be displayed in the form field.

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

TextArea Tag, cont’d Example: Text displayed in TextArea form field.

It supports multiple text lines.

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

What is PHP      

 

Scripting Language Server-side Scripting Embedded Scripts Based on C, C++, and Perl Create web pages dynamically Multi-platform (*nix, Windows) Supports Apache and IIS web server CGI or Server Module 9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Server-side vs Client-side 

Server-side –

Pro    







More secure Client independent Light-weight Client Easier deployment

 

Powerful hardware High server resource High Network resource

9 - 12 April 2007

Pro   



Con 

Client-side Better response Richer user interface No or lighter server requirements

Con   

Less secure Client dependent Challenging Deployment Trainer: Shaizar Md Daud ([email protected])

PHP Basic Construct HTML Section

HTML Title



HTML Section



9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Language Syntax 

Start PHP Section –



End PHP Section –





PHP Statement –

A_php_statement;

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

PHP Comments   



Not executed Source-code documentation Disable parts of codes C-style Comments – –



// Single line comment /* Multi-line comment */

Perl-style Comments (not recommended) –

# Perl-style single line comment

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Day 2  

Using Variables Giving Your Code Life – Flow Control

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Data Types Data Type

Description

String

“text”, „text‟

Integer

-2, -1, 0, 1, 2

Float Boolean

0.4, 1.234 True, false, 0,

Array Object Resource

Database, file 9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Variables 

Syntax – –

   



$my_variable_1 $_my_variable

Case sensitive Container to hold a value or values Values can be changed Variable name starts with an alphabet or underscore Variable name consist of alphabets, underscores, and numbers

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Giving Variables a Value 

Examples – – –

$my_string = “My String”; $my_numbers = 123; $fn_return_value = my_function();

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Arrays   

Stores multiple values in a single variable Stored values can be of different types Index-based or Key-based

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Index-based Array  

Numeric indexes Examples – – –



$index_array[0] = “Item 1”; $index_array[1] = “Item 2”; $index_array[2] = “Item 3”;

Index starts from 0

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Associate Array  

Keys instead of numeric indexes Examples – – –

$kb_array[“one”] = “Item 1”; $kb_array[“two”] = “Item 2”; $kb_array[“three”] = “Item 3”;

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Constants  

Value is fixed once created Example – Creating constants – –



define(“MYCONST”, 23); define(“MYCONSTSTR”, “My String”);

Example – Using constants –

print “The value of MYCONST:” . MYCONST;

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Operators Operator

Description

Operator

=

Assignment

+

Addition

==

Equality

++

Increment

===

Exact Equality

-

Subtraction

Not

--

Decrement

&&

Logical AND

*

Multiply

||

Logical OR

/

Division

%

Modulo

!

>, >=

Greater (or Equal)

20;

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Inserting a Record Syntax: INSERT INTO `table_name` () VALUES (};

Example: INSERT INTO student (st_fname, st_age) VALUES ( „Ahmad Albab‟, 20 );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Updating a Record Syntax: UPDATE table_name SET [ WHERE ];

Example: UPDATE student SET st_fname = „Jat‟, st_age = 22 WHERE st_id = 1;

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Deleting a Record or Records Syntax: DELETE FROM table_name [ WHERE ]; Example:

DELETE FROM student WHERE st_id = 2; DELETE FROM student WHERE st_age < 18;

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

PHP Functions for MySQL PHP Function

Description

mysql_connect()

Connect to a MySQL database server

mysql_select_db()

Make a database active

mysql_query()

Execute SQL statement on active database

mysql_fetch_array()

Fetch a row from query result and return as data as an array of fields and values

mysql_insert_id()

Returns the last inserted ID from an auto_increment field

mysql_error()

Returns the last MySQL error message.

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

mysql_connect() Syntax: resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]]); Example:

$dbh = mysql_connect( „localhost‟, „root‟, „‟ );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

mysql_select_db() Syntax: bool mysql_select_db ( string database_name [, resource link_identifier] ) Example: $stat = mysql_select_db( „training‟, $dbh );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

mysql_query() Syntax: resource mysql_query ( string query [, resource link_identifier] ) Example: $rh = mysql_query( „SELECT * FROM student‟, $dbh );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

mysql_fetch_array() Syntax: array mysql_fetch_array ( resource result [, int result_type] ) Example: $row = mysql_fetch_array( $rh );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

mysql_insert_id() Syntax: int mysql_insert_id( [resource link_identifier] )

Example: $newId = mysql_insert_id( $dbh );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

mysql_error() Syntax: string mysql_error( [resource link_identifier] ) Example:

$errMsg = mysql_error( $dbh );

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Putting It All Together 

Lab Project

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

Thank You   

Shaizar Md Daud @ Jat [email protected] Tel: 012-311 2506

9 - 12 April 2007

Trainer: Shaizar Md Daud ([email protected])

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF