Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation.

Similar presentations


Presentation on theme: "1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation."— Presentation transcript:

1 1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation

2 2 Introduction  PHP PHP: Hypertext Preprocessor Originally called “Personal Home Page Tools” Popular server-side scripting technology Open-source  Anyone may view, modify and redistribute source code  Supported freely by community Platform independent

3 3 Basic Syntax of PHP  Basic application Scripting delimiters   Must enclose all script code Variables preceded by $ symbol  Case-sensitive

4 4 Basic Syntax of PHP End statements with semicolon Comments  // for single line  /* */ for multiline Filenames end with.php by convention

5 5 Declare variable $name Scripting delimiters Single-line comment Function print outputs the value of variable $name

6 6 Basic Syntax of PHP Simple PHP program

7 7 Basic Syntax of PHP Variable  Variable –area of memory set aside to store information, and it is assigned a particular identifier by the programmer.  Begin with a dollar ‘$’ sign.  To assign a value to variable,use the equals sign or assignment ‘= ’ operator. $author = “William Shakespear”;

8 8 Basic Syntax of PHP  Case-sensitive : $author = “William Shakespear”; $Author = “William Shakespear”; Above codes actually create two separate variables

9 9

10 10 Basic Syntax of PHP Data Types

11 11 Basic Syntax of PHP String Data Type  Holds textual information or words, and can even hold full sentences.  Everything stored inside quotation marks automatically becomes text, even numeric data. $CarType= “Cadillac”; $EngineSize=“2.6”;

12 12 Basic Syntax of PHP String Concatenation  The process of adding one string to another – example : Attach one string to the end of another.  Use.(period) as the concatenation operator. $Car= $CarType.$EngineSize; Cadillac2.6

13 13 Basic Syntax of PHP Numeric Data Type  Holds two different numeric data types- integers (whole numbers) & doubles (floating point numbers).  No quotation marks. $an_integer= 33; $another_integer = $a_double= 4.567; $another_double = -23.2

14 14 Basic Syntax of PHP Simple Mathematical Operations  Numerical operators can use to perform mathematical operations. +, *, -, /, % (8%5=3)

15 15

16 16

17 17 Basic Syntax of PHP Type Casting $NewVariable = 13; $NewVariable = (string) $NewVariable ; $NewVariable = 13; $NewVariable = (string) $NewVariable ; $NewVariable = (integer) $NewVariable ;

18 18 Basic Syntax of PHP gettype and settype  gettype()– to determine the current data type of variable. gettype($number);  To display : $number = 5; echo gettype($number); Output :integer  settype()– to specifically set the data type. $number = 10; settype($number, “string”);

19 19 Assign a string to variable $testString Assign a double to variable $testDouble Assign an integer to variable $testInteger

20 20 Print each variable’s value Call function settype to convert the data type of variable $testString to a double. Call function settype to convert the data type of variable $testString to an integer. Convert variable $testString back to a string

21 21 Use type casting to cast variable $data to different types

22 22 Type conversion

23 23 Basic Syntax of PHP Constants  An identifier, which takes a value that cannot be changed. The Define Keyword  Need a special keyword define.  Don’t need to be prefixed with a dollar sign.  Constant names are by convention all in upper case. define(“FREEZINGPOINTCENTIGRADE”, 0); Constant nameConstant value

24 24 Basic Syntax of PHP  Constant that contains text – enclose the constant value with quotation marks, example : define(“INDEPENDENCEDAY”, “31 st August”); define(“COUNTRY”, “Malaysia”);  You can use echo() to display constants on web pages.  You can also append them to text, by using the concatenate operator. echo “Independence Day is on”. INDEPENDENCEDAY ;

25 25 Basic Syntax of PHP  Always make sure that constant name appears outside the quotation marks. echo “Independence Day is on INDEPENDENCEDAY”; OUTPUT = Independence Day is the INDEPENDENCEDAY  PHP also has its own built-in constants, example: echo PHP_OS; (use to reflect values of OS that PHP is running on)

26 26 Getting Data From Client Notes can be obtained from:

27 27 PHP Database Manipulation  PHP supports for a wide range of databases.  The following databases are currently supported:  Adabas DInterBase  PostgreSQL  dBase  FrontBase  SQLite  Empress  mSQL  Solid  Direct MS-SQL  Sybase  Hyperwave  MySQL  Velocis  IBM DB2  ODBC  Unix dbm  Informix  Oracle (OCI7 and OCI8)  Ingres

28 28 What is MySQL?  MySQL is a small database server  MySQL is ideal for small and medium applications  MySQL supports standard SQL  MySQL compiles on a number of platforms  MySQL is free to download and use

29 29 Connecting to Database Connect Server

30 30 Inserting Data into Database form_insert_record.php Birthdays Insert Form Insert Record

31 31 Inserting Data into Database print "Enter Birthday: \n"; print " \n"; ?>

32 32 Inserting Data into Database insert.php

33 33 Displaying Data from Database display.php (Title Here)

34 34 Displaying Data from Database print "There are $num_rows records. "; print " \n"; while ($get_info = mysql_fetch_row($result)){ print " \n"; foreach ($get_info as $field) print "\t $field \n"; print " \n"; } print " \n"; mysql_close($link); ?>

35 35 Deleting Data from Database form_delete.php Birthdays Delete Form

36 36 Deleting Data from Database print "There are $num_rows records. "; print " \n"; while ($get_info = mysql_fetch_row($result)){ print " \n"; foreach ($get_info as $field) print "\t $field \n"; print " \n"; } print " \n"; mysql_close($link); ?>

37 37 Deleting Data from Database Enter Line Number to Delete:

38 38 Deleting Data from Database delete.php


Download ppt "1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation."

Similar presentations


Ads by Google