Php tutorial


Published on

Basic Php tutorial

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Php tutorial

  1. 1. VIJAY SHARMA PHP TUTORIAL PHP Programming With My SQL Connection
  2. 2. VIJAY SHARMA PHP: The Basics  Why PHP and MySQL?
  3. 3. 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.
  4. 4. 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.
  5. 5. 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
  6. 6. 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:  It is an efficient alternative to competitors such as Microsoft's ASP.
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. VIJAY SHARMA PHP Syntax  A PHP scripting block always starts with <?php and ends with ?>  <?php……………. ?>
  11. 11. 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>
  12. 12. 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.
  13. 13. 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!‘  ?>
  14. 14. 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:
  15. 15. 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;
  16. 16. VIJAY SHARMA  print "<table border=1 cellpadding=3>";  while ( $start <=10 )  {  mul();  $start++;  }  print "</table>";  ?>