Php tutorial
description
Transcript of Php tutorial
VIJAY SHARMA
PHP TUTORIAL
PHP Programming With
My SQL Connection
www.kumarvijaybaswa.blogspot.com
VIJAY SHARMA
PHP: The Basics
Why PHP and MySQL?
VIJAY SHARMA
What Is PHP?
PHP is the Web development language written by and for Web developers.
PHP stands for PHP: Hypertext Preprocessor. The product was originally named Personal Home Page Tools, and many people still think that’s what the acronym stands for. But as it expanded in scope, a new and more appropriate name was selected by community vote. PHP is currently in its fifth major rewrite, called PHP5 or just plain PHP.
VIJAY SHARMA
Server-Side Scripting
A “script” is a collection of program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor.
Client-side Server-side In server-side scripting, (such as PHP, ASP) the script is processed by the
server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows. Client-side scripting such as JavaScript runs on the web browser.
VIJAY SHARMA
Advantages of Server-Side Scripting
Dynamic content. Computational capability. Database and file system access. Network access (from the server only). Built-in libraries and functions. Known platform for execution (as opposed
to client-side, where the platform is uncontrolled.) Security improvements
VIJAY SHARMA
INTRODUCTION TO PHP PHP stands for PHP: Hypertext Preprocessor Developed by Rasmus Lerdorf in 1994 It is a powerful server-side scripting language for creating
dynamic and interactive websites. It is an open source software, which is widely used and free to
download and use (PHP is FREE to download from the official PHP resource: www.php.net).
It is an efficient alternative to competitors such as Microsoft's ASP.
VIJAY SHARMA
PHP is perfectly suited for Web development and can be embedded directly into the HTML code.
The PHP syntax is very similar to JavaScript, Perl and C. PHP is often used together with Apache (web server) on
various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows.
PHP supports many databases (MySQL, Informix, Oracle, Sybase,
Solid, PostgreSQL, Generic ODBC, etc.)
INTRODUCTION TO PHP
VIJAY SHARMA
What is a PHP File?
PHP files have a file extension of ".php", ".php3", or
".phtml" PHP files can contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML
INTRODUCTION TO PHP
VIJAY SHARMA
What you need to develop PHP Application:
Install Apache (or IIS) on your own server, install PHP, and MySQL
Install Wampserver2 or XAMPP (a bundle of PHP, Apache, and MySql server) on your own server/machine
INTRODUCTION TO PHP
VIJAY SHARMA
PHP Syntax
A PHP scripting block always starts with <?php and ends with ?>
<?php……………. ?>
VIJAY SHARMA
Example simple html & php page PHP and HTML Code:<html> <head> <title>My First PHP Page</title> </head> <body> <?php echo "Hello World!"; ?> </body> </html>
VIJAY SHARMA
PHP VARIABLES Variables are used for storing values, such as
numbers, strings or function results, so that they can be used many times in a script.
All variables in PHP start with a $ sign symbol. Variables are assigned using the assignment operator "=“ Variable names are case sensitive in PHP: $name is not the same as $NAME or $Name. In PHP a variable does not need to be declared before
being set. PHP is a Loosely Typed Language.
VIJAY SHARMA
Example: <?php $var1 = 'PHP'; // Assigns a
value of 'PHP' to $var1 $var2 = 5; // Assigns a value
of 5 to $var2 $var3 = $var2 + 1; // Assigns
a value of 6 to $var3 $var2 = $var1; // Assigns a
value of 'PHP' to $var2 echo $var1; // Outputs 'PHP‘ echo "<br />";
echo $var2; // Outputs 'PHP' echo "<br />"; echo $var3; // Outputs '6' echo "<br />"; echo $var1 . ' rules!'; //
Outputs 'PHP rules!' echo "$var1 rules!"; //
Outputs 'PHP rules!' echo '$var1 rules!'; // Outputs
'$var1 rules!‘ ?>
VIJAY SHARMA
VARIABLE SCOPE AND LIFETIME
The scope of a variable defined within a function is local to that function. A variable defined in the main body of code
has a global scope. If a function needs to use a variable that is defined in the main body of the program, it must reference it using the "global"
keyword, like this:
VIJAY SHARMA
Example: <?php function mul() { global $start; print "<tr>"; for ($num=1; $num <= 10; $num++ ) { $cell = $num * $start; print "<td> " . $cell . " </td>"; } print "</tr>"; } $start = 0;
VIJAY SHARMA
print "<table border=1 cellpadding=3>";
while ( $start <=10 ) { mul(); $start++; } print "</table>"; ?>