42
PHP + My SQL AUD©

Php + my sql

Embed Size (px)

DESCRIPTION

Php My Sql Basic

Citation preview

Page 1: Php + my sql

PHP + My SQLAUD©

Page 2: Php + my sql
Page 3: Php + my sql

What is PHP?

PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like

ASP PHP scripts are executed on the server PHP supports many databases (MySQL,

Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)

PHP is an open source software PHP is free to download and use

Page 4: Php + my sql

What is a PHP File?

PHP files can contain text, HTML tags and scripts

PHP files are returned to the browser as plain HTML

PHP files have a file extension of ".php", ".php3", or ".phtml"

Page 5: Php + my sql

What is MySQL?

MySQL is a database server MySQL is ideal for both small and large

applications MySQL supports standard SQL MySQL compiles on a number of

platforms MySQL is free to download and use

Page 6: Php + my sql

PHP + MySQL

PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Page 7: Php + my sql

Why PHP?

PHP runs on different platforms (Windows, Linux, Unix, etc.)

PHP is compatible with almost all servers used today (Apache, IIS, etc.)

PHP is FREE to download from the official PHP resource: www.php.net

PHP is easy to learn and runs efficiently on the server side

Page 8: Php + my sql

Start With PHP To start with PHP you will need to install

PHP 5.0 or higher. In addition to PHP you should install MY

SQL as database You can download PHP from

Page 9: Php + my sql

How the PHP works

Page 10: Php + my sql

OOP What Is an Object?

An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.

What is a class? Class is a collection of a objects with

common properties.

Page 11: Php + my sql

Object Software objects are conceptually similar to real-

world objects: they too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages). Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication. Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming.

Page 12: Php + my sql

Object Objects are key to understanding object-oriented

technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior. Dogs have state<attributes> (name, color, breed,

hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal

cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.

Page 13: Php + my sql

Class

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

Page 14: Php + my sql

What Is Inheritance? Different kinds of objects often have a certain amount in common with

each other. Mountain bikes, road bikes, and tandem bikes,

for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

Page 15: Php + my sql

Inheritance

Page 16: Php + my sql

Interface Interface makes the relationship

between classes and functionality to those classes implement easier to understand and to design

A interface is a collection of methods that indicate a class has some behavior in addition to what in inherits from supper class;

Page 17: Php + my sql

Packages Packages are use to grouping related

classes and interfaces Java has many packages than make our

work lot easier For take advantages of other packages

you must import them

Page 18: Php + my sql

Basic PHP Syntax

A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.

Page 19: Php + my sql

<html><body>

<?phpecho "Hello World";?>

</body></html>

Page 20: Php + my sql

<html><body>

<?php//This is a comment

/*This isa commentblock*/?>

</body></html>

Page 21: Php + my sql

Variables in PHP

Variables in PHP Variables are used for storing values,

like text strings, numbers or arrays. When a variable is declared, it can be

used over and over again in your script. All variables in PHP start with a $ sign

symbol.

Page 22: Php + my sql

Keywords

Page 23: Php + my sql

Variable ex $var_name = value; <?php

$txt="Hello World!";$x=16;?>

<?php$txt="Hello World";echo $txt;?>

Page 24: Php + my sql

Variable Ex <?php

$txt1="Hello World!";$txt2="What a nice day!";echo $txt1 . " " . $txt2;?>

Page 25: Php + my sql

Strlen & strpos   <?php

echo strlen("Hello world!");?>

<?phpecho strpos("Hello world!","world");?>

Page 26: Php + my sql

Array The array functions allow you to

manipulate arrays. PHP supports both simple and multi-

dimensional arrays. There are also specific functions for populating arrays from database queries.

Syntax array(key => value)

Page 27: Php + my sql

Array <?php

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");

print_r($a);?>

<?php$arr = array("foo" => "bar", 12 => true);

echo $arr["foo"]; echo $arr[12];    

?>

Page 28: Php + my sql

Array <?php

$arr = array(“Horana”,”Colombo”,”Nuwar aeliya”,”Kandi”);

echo $arr[1]; echo $arr[4];    

?>

Page 29: Php + my sql

PHP Operators

Operator Description Example Result

+ Addition x=2x+2

4

- Subtraction x=25-x

3

* Multiplication x=4x*5

20

/ Division 15/55/2

32.5

% Modulus (division remainder) 5%210%810%2

120

++ Increment x=5x++

x=6

-- Decrement x=5x--

x=4

Arithmetic Operators

Page 30: Php + my sql

Assignment Operators

Operator Example Is The Same As

= x=y x=y

+= x+=y x=x+y

-= x-=y x=x-y

*= x*=y x=x*y

/= x/=y x=x/y

.= x.=y x=x.y

%= x%=y x=x%y

Page 31: Php + my sql

Comparison operatorsOperator Description Example

== is equal to 5==8 returns false

!= is not equal 5!=8 returns true

<>  is not equal 5<>8 returns true

>  is greater than 5>8 returns false

<  is less than 5<8 returns true

>= is greater than or equal to 5>=8 returns false

<= is less than or equal to 5<=8 returns true

Page 32: Php + my sql

Logical Operators

Operator Description Example

&& and x=6y=3

(x < 10 && y > 1) returns true

|| or x=6y=3

(x==5 || y==5) returns false

! not x=6y=3

!(x==y) returns true

Page 33: Php + my sql

Flow Control IF else Switch While Do while For

Page 34: Php + my sql

IF else

Page 35: Php + my sql

IF else Ex1 <?php

$n1 = 50;if(n1>=50){

echo “Pass”;}else{

echo “faille”}?>

Page 36: Php + my sql

Switch <?php$i = 281;

switch ($i) {    case “281":        echo “Thalgahavila Road";        break;    case “315":        echo “Meeme Road";        break;    case “120":        echo “Colombo Road";        break;}?>

Page 37: Php + my sql

While

Page 38: Php + my sql

While ex <?php

$i=0;while ($i<5){echo $i." "."AuD©"."<br/>";$i++;}

?>

Page 39: Php + my sql

Do While <?php

$i=0;do{echo $i." "."AuD©"."<br/>";$i++;}while ($i<5)

?>

Page 40: Php + my sql

For

Page 41: Php + my sql

For <?php

for($i=0;$i<5;$i++){echo $i." "."AuD©"."<br/>";

}

?>

Page 42: Php + my sql

For each <?php$x=array("Ashen","Upendra","Disanayaka");foreach($x as $value){echo $value." ".".......AuD©.........";} ?>