Introduction to PHP •Server-Side Scripting •MYSQL •PHP •Apache •Variables •Control Structure •Looping
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.
 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
• 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 to develop dynamic websites. • It is an efficient alternative to competitors such as Microsoft's ASP.
• 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, Postgre SQL, Generic ODBC, etc.)
• 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
What you need to develop PHP Application: • Install Apache (or IIS) on your own server, install PHP, and MySQL • OR • Install Wampserver2 (a bundle of PHP, Apache, and MySql server) on your own server/machine
• When a PHP document is requested of a server, the server will send the document first to a PHP processor • Two modes of operation – Copy mode in which plain HTML is copied to the output – Interpret mode in which PHP code is interpreted and the output from that code sent to output – The client never sees PHP code, only the output produced by the code
• PHP statements are terminated with semicolons ; • Curly braces, { } are used to create compound statements • Variables cannot be defined in a compound statement unless it is the body of a function • PHP has typical scripting language characteristics – – – – Dynamic typing, un-typed variables Associative arrays Pattern matching Extensive libraries • Primitives, Operations, Expressions – Four scalar types: boolean, integer, double, string – Two compound types: array, object – Two special types: resource and NULL
• A PHP scripting block always starts with <?php and ends with ?> <?php ……………. ?> – Other options are: 1. <? ……………… ?> 2. <script> ... </script> • There are three basic statements to output text with PHP: echo, print, and printf. Example: echo 'This is a <b>test</b>!'; • Comments: – # – // – /* . . . */
Basic PHP Syntax  Inserting external files:  PHP provides four functions that enable you to insert code from external files: include() or require() include_once() or require_once() functions. • E.g.  include("table2.php"); – Included files start in copy mode
Example 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple PHP Example</title> <body> <?php echo "Hello Class of 2011. This is my first PHP Script"; echo "<br />"; print "<b><i>What have you learnt and how many friends have you made?</i></b>"; echo "<br /><a href='PHP I-BSIC.ppt'>PHP BASIC</a>"; ?> </body> </html>
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.
Strings in PHP • • • a string is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes. String literals are enclosed in single or double quotes Example: <?php $sum = 20; echo 'the sum is: $sum'; echo "<br />"; echo "the sum is: $sum"; echo "<br />"; echo '<input type="text" name="first_name" id="first_name">'; ?> – Double quoted strings have escape sequences (such as /n or /r) interpreted and variables interpolated (substituted) – Single quoted strings have neither escape sequence interpretation nor variable interpolation – A literal $ sign in a double quoted string must be escaped with a backslash, – Double-quoted strings can cover multiple lines
PHP Function  In php a function is a predefined set of commands that are carried out when the function is called.  The real power of PHP comes from its functions.  PHP has more than 700 built-in or predefine functions for you to use.
Using Built-in Function  Examples: Inserting external files:  PHP provides four functions that enable you to insert code from external files: include() or require() include_once() or require_once() functions.  A sample include file called add.php <html> <body> <?php function add( $x, $y ) { return $x + $y; } ?> <h1>Welcome to my home page</h1> <p>Some text</p> </body> </html> Using the include function <?php include('add.php'); echo add(2, 2); ?>
PHP Functions - Adding parameters  A parameter is just like a variable.  The parameters are specified inside the parentheses. Syntax: <?php function function_name(param_1, ... , param_n) { statement_1; statement_2; ... statement_m; ?> } return return_value;
PHP Functions - Adding parameters  Functions can also be used to return values. Example:   <html> <body>       <?php function add($x,$y) { $total = $x + $y; return $total; }   echo "1 + 16 = " . add(1,16); ?>   </body> </html>
Control Structure  Control structures are the building blocks of any programming language. PHP provides all the control structures that you may have encountered anywhere. The syntax is the same as C or Perl.  Making computers think has always been the goal of the computer architect and the programmer. Using control structures computers can make simple decisions and when programmed cleverly they can do some complex things.
PHP Switch Statement • If you want to select one of many blocks of code to be executed, use the Switch statement. • The switch statement is used to avoid long blocks of if..elseif..else code. Syntax switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; }
PHP Switch Statement               switch ($textcolor) { case "black": echo "I'm black"; break; case "blue": echo "I'm blue"; break; case "red": echo "I'm red"; break; default: // It must be something else echo "too bad!!, I'm something else"; }
PHP Looping • Looping statements in PHP are used to execute the same block of code a specified number of times. • In PHP we have the following looping statements: – while - loops through a block of code if and as long as a specified condition is true – do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true – for - loops through a block of code a specified number of times – foreach - loops through a block of code for each element in an array
The while Statement Syntax while (condition) { // statements } Example <html> <head> <title>Let us count !!!</title></head> <body> <?php $limit = 10; echo "<h2> Let us count from 1 to $limit </h2><br />"; $count = 1; while ($count <= $limit) { echo "counting $count of $limit <br>"; $count++; } ?> </body> <html>
The do...while Statement • The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true. Syntax • do { code to be executed; } while (condition);         Example <html> <body> <?php $i=0; do { $i++; echo "The number is " . $i . "<br />"; } while ($i<5); ?> </body> </html>
PHP Arrays  An array can store one or more values in a single variable name.  There are three different kind of arrays:  Numeric array - An array with a numeric ID key  Associative array - An array where each ID key is associated with a value  Multidimensional array - An array containing one or more arrays
Numeric Array • A numeric array stores each element with a numeric ID key. • There are different ways to create a numeric array: Example 1 • In this example the ID key is automatically assigned: • $names = array("Peter","Quagmire","Joe"); Example 2 • In this example we assign the ID key manually: $names[0] = "Peter"; $names[1] = "Quagmire"; $names[2] = "Joe";
Associative Arrays • Each ID key is associated with a value. • When storing data about specific named values, a numerical array is not always the best way to do it. • There are two ways of creating Associative Array: Example 1 • $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Example 2 • $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34";
Multidimensional Arrays • In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. • Example 1 • with automatically assigned ID keys: $families = array ( "Griffin"=>array ( "Peter", "Lois", "Megan" ), "Quagmire"=>array ( "Glenn" ), "Brown"=>array ( "Cleveland", "Loretta", "Junior" ) );
Multidimensional Arrays   Example 2: The array above would look like this if written to the output:    Array ( [Griffin] => Array  (  [0] => Peter  [1] => Lois  [2] => Megan  ) [Quagmire] => Array  (  [0] => Glenn  ) [Brown] => Array  (  [0] => Cleveland  [1] => Loretta  [2] => Junior )  )   • displaying a single value from the array above:  echo "Is " . $families['Griffin'][2] . " a part of the Griffin family?";

Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,best php-mysql classes in navi-mumbai

  • 1.
    Introduction to PHP •Server-SideScripting •MYSQL •PHP •Apache •Variables •Control Structure •Looping
  • 2.
    A “script” isa 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.
  • 3.
     Advantages ofServer-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
  • 4.
    • PHP standsfor 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 to develop dynamic websites. • It is an efficient alternative to competitors such as Microsoft's ASP.
  • 5.
    • PHP isperfectly 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, Postgre SQL, Generic ODBC, etc.)
  • 6.
    • What isa 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
  • 7.
    What you needto develop PHP Application: • Install Apache (or IIS) on your own server, install PHP, and MySQL • OR • Install Wampserver2 (a bundle of PHP, Apache, and MySql server) on your own server/machine
  • 8.
    • When aPHP document is requested of a server, the server will send the document first to a PHP processor • Two modes of operation – Copy mode in which plain HTML is copied to the output – Interpret mode in which PHP code is interpreted and the output from that code sent to output – The client never sees PHP code, only the output produced by the code
  • 9.
    • PHP statementsare terminated with semicolons ; • Curly braces, { } are used to create compound statements • Variables cannot be defined in a compound statement unless it is the body of a function • PHP has typical scripting language characteristics – – – – Dynamic typing, un-typed variables Associative arrays Pattern matching Extensive libraries • Primitives, Operations, Expressions – Four scalar types: boolean, integer, double, string – Two compound types: array, object – Two special types: resource and NULL
  • 10.
    • A PHPscripting block always starts with <?php and ends with ?> <?php ……………. ?> – Other options are: 1. <? ……………… ?> 2. <script> ... </script> • There are three basic statements to output text with PHP: echo, print, and printf. Example: echo 'This is a <b>test</b>!'; • Comments: – # – // – /* . . . */
  • 11.
    Basic PHP Syntax Inserting external files:  PHP provides four functions that enable you to insert code from external files: include() or require() include_once() or require_once() functions. • E.g.  include("table2.php"); – Included files start in copy mode
  • 12.
    Example 1 <!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple PHP Example</title> <body> <?php echo "Hello Class of 2011. This is my first PHP Script"; echo "<br />"; print "<b><i>What have you learnt and how many friends have you made?</i></b>"; echo "<br /><a href='PHP I-BSIC.ppt'>PHP BASIC</a>"; ?> </body> </html>
  • 13.
    PHP Variables • Variablesare 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.
  • 14.
    Strings in PHP • • • astring is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes. String literals are enclosed in single or double quotes Example: <?php $sum = 20; echo 'the sum is: $sum'; echo "<br />"; echo "the sum is: $sum"; echo "<br />"; echo '<input type="text" name="first_name" id="first_name">'; ?> – Double quoted strings have escape sequences (such as /n or /r) interpreted and variables interpolated (substituted) – Single quoted strings have neither escape sequence interpretation nor variable interpolation – A literal $ sign in a double quoted string must be escaped with a backslash, – Double-quoted strings can cover multiple lines
  • 15.
    PHP Function  Inphp a function is a predefined set of commands that are carried out when the function is called.  The real power of PHP comes from its functions.  PHP has more than 700 built-in or predefine functions for you to use.
  • 16.
    Using Built-in Function Examples: Inserting external files:  PHP provides four functions that enable you to insert code from external files: include() or require() include_once() or require_once() functions.  A sample include file called add.php <html> <body> <?php function add( $x, $y ) { return $x + $y; } ?> <h1>Welcome to my home page</h1> <p>Some text</p> </body> </html> Using the include function <?php include('add.php'); echo add(2, 2); ?>
  • 17.
    PHP Functions -Adding parameters  A parameter is just like a variable.  The parameters are specified inside the parentheses. Syntax: <?php function function_name(param_1, ... , param_n) { statement_1; statement_2; ... statement_m; ?> } return return_value;
  • 18.
    PHP Functions -Adding parameters  Functions can also be used to return values. Example:   <html> <body>       <?php function add($x,$y) { $total = $x + $y; return $total; }   echo "1 + 16 = " . add(1,16); ?>   </body> </html>
  • 19.
    Control Structure  Controlstructures are the building blocks of any programming language. PHP provides all the control structures that you may have encountered anywhere. The syntax is the same as C or Perl.  Making computers think has always been the goal of the computer architect and the programmer. Using control structures computers can make simple decisions and when programmed cleverly they can do some complex things.
  • 20.
    PHP Switch Statement •If you want to select one of many blocks of code to be executed, use the Switch statement. • The switch statement is used to avoid long blocks of if..elseif..else code. Syntax switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; }
  • 21.
    PHP Switch Statement               switch($textcolor) { case "black": echo "I'm black"; break; case "blue": echo "I'm blue"; break; case "red": echo "I'm red"; break; default: // It must be something else echo "too bad!!, I'm something else"; }
  • 22.
    PHP Looping • Loopingstatements in PHP are used to execute the same block of code a specified number of times. • In PHP we have the following looping statements: – while - loops through a block of code if and as long as a specified condition is true – do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true – for - loops through a block of code a specified number of times – foreach - loops through a block of code for each element in an array
  • 23.
    The while Statement Syntax while(condition) { // statements } Example <html> <head> <title>Let us count !!!</title></head> <body> <?php $limit = 10; echo "<h2> Let us count from 1 to $limit </h2><br />"; $count = 1; while ($count <= $limit) { echo "counting $count of $limit <br>"; $count++; } ?> </body> <html>
  • 24.
    The do...while Statement • Thedo...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true. Syntax • do { code to be executed; } while (condition);         Example <html> <body> <?php $i=0; do { $i++; echo "The number is " . $i . "<br />"; } while ($i<5); ?> </body> </html>
  • 25.
    PHP Arrays  Anarray can store one or more values in a single variable name.  There are three different kind of arrays:  Numeric array - An array with a numeric ID key  Associative array - An array where each ID key is associated with a value  Multidimensional array - An array containing one or more arrays
  • 26.
    Numeric Array • Anumeric array stores each element with a numeric ID key. • There are different ways to create a numeric array: Example 1 • In this example the ID key is automatically assigned: • $names = array("Peter","Quagmire","Joe"); Example 2 • In this example we assign the ID key manually: $names[0] = "Peter"; $names[1] = "Quagmire"; $names[2] = "Joe";
  • 27.
    Associative Arrays • EachID key is associated with a value. • When storing data about specific named values, a numerical array is not always the best way to do it. • There are two ways of creating Associative Array: Example 1 • $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Example 2 • $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34";
  • 28.
    Multidimensional Arrays • Ina multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. • Example 1 • with automatically assigned ID keys: $families = array ( "Griffin"=>array ( "Peter", "Lois", "Megan" ), "Quagmire"=>array ( "Glenn" ), "Brown"=>array ( "Cleveland", "Loretta", "Junior" ) );
  • 29.
    Multidimensional Arrays   Example 2: Thearray above would look like this if written to the output:    Array ( [Griffin] => Array  (  [0] => Peter  [1] => Lois  [2] => Megan  ) [Quagmire] => Array  (  [0] => Glenn  ) [Brown] => Array  (  [0] => Cleveland  [1] => Loretta  [2] => Junior )  )   • displaying a single value from the array above:  echo "Is " . $families['Griffin'][2] . " a part of the Griffin family?";