INTRODUCTION TO PHP/ INTRODUCTION TO PHP/MYSQL ... - FTSM

204 downloads 1927 Views 2MB Size Report
23 Sep 2010 ... Provide the basic knowledge of PHP programming. □ Explain how ... Each PHP script must be enclosed in the reserved PHP tag .... kumpulan).
INTRODUCTION TO PHP/MYSQL PHP/MYSQL I

FTSM Lab / May 2011

Goal 

Provide the basic knowledge of PHP programming Explain how you can code and run PHP scripts Creating dynamic pages  Basic database interactions – read, insert, update and delete data  

Structure HTML/ XHTML PHP

Database

CSS JavaScript

1

HTML/JavaScript/CSS  

http://www.w3schools.com HTML, JavaScript and CSS tutorials

Client-server architecture

What is PHP?  





PHP = ‘Hypertext PreProcessor’ Originally created by Rasmus Lerdorf in 1994 The main implementation of PHP is now produced by The PHP Group (de facto standard for PHP) - http://www.php.net/ Open-source (access to source code and free distribution right), server-side scripting language

2

How PHP works

How to run PHP scripts PHP on Windows Method1

Method2

IIS

Apache

FastCGI + PHP

PHP

mySQL

mySQL

Method3 WAMP Packages

Method4 Web Hosting

Webhosting 

Webhosting information

3

WAMP Packages - XAMPP 



http://www.apachefriends.org/en/index.html

Version for Windows includes: Apache, MySQL, PHP, Perl, phpMyAdmin, JpGraph, FileZilla FTP Server, SQLite etc.

WAMP Packages - WAMPServer 



http://www.wampserver.com/en/

Version for Windows includes: Apache, PHP, Mysql (version 64 and 32 bits), PhpMyadmin, SQLBuddy, XDebug, webGrind, XDC

PHP Scripts Basic syntaxes, data types, variable, control structures, arrays, function

4

PHP BASIC SYNTAX

DATA TYPE FUNCTION

VARIABLES CONTROL STATEMENTS

DATABASE CONNECT/ READ

SESSION

INSERT

UPDATE

DELETE

PHP PACKAGES

PHP code   

Structurally similar to C/C++ All PHP statements end with a semi-colon Each PHP script must be enclosed in the reserved PHP tag



PHP code - comments 

Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */

5

PHP code - output  

Use ‘echo’ or ‘print’ Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP

// Numerical variable // String variable

$ayat; $nilai, $ayat; “5x5=”,$nilai; “5x5=$nilai”; ‘5x5=$nilai’;

// // // // //

Outputs Outputs Outputs Outputs Outputs

Hello 25Hello 5x5=25 5x5=25 5x5=$nilai

PHP – escape character 

If the string has a set of double quotation marks that must remain visible, use the \ [backslash] before the quotation marks to ignore and display them.

PHP code - variables   

PHP variables must begin with a “$” sign Case-sensitive ($var != $VAR != $vAr) Global and locally-scoped variables  



Global variables can be used anywhere Local variables restricted to a function or class

Certain variable names reserved by PHP  

Form variables ($_POST, $_GET) Server variables ($_SERVER)

6

PHP code – variables

PHP code - operations

PHP code – strings function 

Use a period to join strings into one.



7

PHP – Control Statements 

Control structures similar with JavaScript/C++  if, elseif, else  switch, case  while  for  foreach

PHP - if, elseif elseif,, else

PHP control – for loops

PHP control – foreach loops

9

PHP arrays 

Three kind of arrays:  Numeric array - An array with a numeric index  Associative array - An array where each ID key is associated with a value  Multidimensional array - An array containing one or more arrays

PHP – numeric arrays

Suggest Documents