Learn PHP MySQL in 2 Days : Day 1 of 2

Learn PHP MySQL in 2 Days

What is PHP ?

PHP is web development language basically written by the developer and used by the developer. PHP is very easy to learn language as compared to any other language. The initial full form of PHP is Personal Home Page and now its known as Hypertext PreProcessor.

Why PHP is easy ?

PHP follows syntax as similar to C or CPP language. Basically Every programmer knows C Language and if you know C Language then its very easy to Start with PHP Language.

PHP Version History.

Version

Release date

1.0

8 June 1995

2.0

1 November 1997

3.0

6 June 1998

4.0

22 May 2000

4.1

10 December 2001

4.2

22 April 2002

4.3

27 December 2002

4.4

11 July 2005

5.0

13 July 2004

5.1

24 November 2005

5.2

2 November 2006

5.3

30 June 2009

Benefits of PHP and MySQL

Costing

Easy to Use

HTML embedded

Cross Platform Compatibility

Stability

Many Extension

Open Source

Strong User Help by Forum and Communities

Which kind of website you can develop using PHP

Blog

Personal Website

E-Commerce Website

Advertisement Website

Content Website

Survey Website

Poll Website

Counter Website

Forum

Group Website

Games

General Website

PHP Basic Tag (Starting and Ending Delimiter for PHP )

1

<?php?>

PHP Other Tags but Not Recommended Tags

1

2

3

"<script language="php">" and "</script>"

Shortopening tags(<?or<?=)

ASP style tags(<%or<%=)

Hello World PHP Example ( FileName: index.php)

1

2

3

4

5

6

7

8

9

10

<HTML>

<HEAD>

<TITLE>PHPHelloWorldbyAdarshPatel</TITLE>

</HEAD>

<BODY>

<?php

echo"Hello, World";

?>

</BODY>

</HTML>

PHP Variables

In PHP Variable are prefixed with a dollar symbol and type does not need to specify. In PHP Variable declaration is not required. you can directly add values and type will be selected automatically by PHP.

PHP Variable Example 1

1

2

3

4

<?php

$hello=“Hello using Variable”;

echo“$hello”;

?>

PHP Variable Example 2 (Find Sum of Two Numbers)

1

2

3

4

5

6

<?php

$no1=10;

$no2=20;

$no3=$no1+$no2;

echo“$no1+$no2=$no3”;

?>

PHP Variable Example 3 (Contact Two String)

1

2

3

4

5

6

<?php

$v1="Adarsh";

$v2=" Patel";

$v3=$v1.$v2;

echo"$v3";

?>

PHP Variable Example 4 (Contact Two String) (Wrong)

1

2

3

4

5

6

<?php

$v1="Adarsh";

$v2=" Patel";

$v3=$v1+$v2;

echo"$v3";

?>

PHP Variable Example 5

1

2

3

4

5

6

<?php

$v1=5;

echo$v1;

$v1="This is Sample String";

echo"$v1";

?>

Its 0 or empty string is default for all PHP Variables.

PHP Comments Format

1

2

3

/* */which serves asblock comments,and

// one line comments

# inline commenting

Isset() to check Variable is Live or not

1

2

3

4

5

6

7

8

<?php

$v1=5;

if(isset($v1))

echo$v1;

else

echo"Variable issetup yet";

?>

unset() to deallocate memory of Variable

1

2

3

4

5

6

7

8

9

10

<?php

$v1=5;

if(isset($v1))

{

unset($v1);

echo$v1;//will throws error Undefined Variable

}

else

echo"Variable is not setup yet";

?>

PHP Constants

In Addition to PHP Variables you can declare constants in your PHP also. Once you declare PHP Constants then you can not change value of it.

1

2

3

4

5

<?php

define(NUMBER1,1234);

echo"My Number is : ".$NUMBER1;

echo"My Number is : ".NUMBER1;

?>

Operators Supported in PHP

Logical Operators

Operator

Description

and

Is true if and only if both of its arguments are true

or

Is true if either (or both) of its arguments are true.

!

Is true if its single argument (to the right) is false and false if its argument is true.

Comparison Operators

Operator

Description

==

Equal

!=

Not Equal

<

Less Than

>

Grate Than

<=

Lessthan or Equal to

>=

Grater than or Equal to

===

Identical

True if its arguments are equal to each other and of the same type but false otherwise