Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Php Training

10,308 views

Published on

php training

  • Login to see the comments

Php Training

  1. 1. Web Server <ul><li>Web server: IIS, Apache </li></ul><ul><li>Script Language: ASP, PHP.. </li></ul><ul><li>Database: mysql, mssql… </li></ul>
  2. 2. Operation Principles
  3. 3. What is PHP? <ul><li>PHP stands for P HP: H ypertext P reprocessor. </li></ul><ul><li>PHP is a server-side scripting language, like ASP </li></ul><ul><li>-PHP scripts are executed on the server </li></ul><ul><li>-PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) </li></ul><ul><li>-PHP is an open source software </li></ul><ul><li>-PHP is free to download and use </li></ul>
  4. 4. 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 &quot;.php&quot;, &quot;.php3&quot;, or &quot;.phtml“.
  5. 5. 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.
  6. 6. LAMP <ul><li>L : Linux(Fedora, CentOS, Debian, Ubuntu). </li></ul><ul><li>A : Apache. </li></ul><ul><li>M : Mysql. </li></ul><ul><li>P : PHP. </li></ul>
  7. 7. PHP Syntax <ul><li><?php echo &quot;Hello World&quot;; ?> </li></ul><ul><li>//This is a comment </li></ul><ul><li>/* This is a comment block */ </li></ul>
  8. 8. PHP Variables <ul><li>$var_name = value; </li></ul><ul><li><?php $txt=&quot;Hello World!&quot;; $x=16; ?> </li></ul><ul><li>a-z, A-Z, 0-9, and _ </li></ul>
  9. 9. PHP String Variables <ul><li><?php $txt=&quot;Hello World&quot;; echo $txt;// Hello World ?> </li></ul><ul><li><?php $txt1=&quot;Hello World!&quot;; $txt2=&quot;What a nice day!&quot;; echo $txt1 . &quot; &quot; . $txt2; ?> </li></ul><ul><li><?php echo strlen(&quot;Hello world!&quot;); </li></ul><ul><li>// 12 </li></ul><ul><li>?> </li></ul><ul><li><?php echo strpos(&quot;Hello world!&quot;,&quot;world&quot;); </li></ul><ul><li>//6 ?> </li></ul>
  10. 10. PHP Operators -Arithmetic Operators -Assignment Operators - Comparison Operators -Logical Operators
  11. 11. PHP Operators (Arithmetic)
  12. 12. PHP Operators (Assignment )
  13. 13. PHP Operators (Comparison)
  14. 14. PHP Operators (Logical)
  15. 15. PHP If...Else Statements <ul><li>if ( condition )    code to be executed if condition is true; else    code to be executed if condition is false; </li></ul><ul><li><?php $d=date(&quot;D&quot;); if ($d==&quot;Fri&quot;)   echo &quot;Have a nice weekend!&quot;; else   echo &quot;Have a nice day!&quot;; ?> </li></ul>
  16. 16. PHP Switch Statement <ul><li>switch ( n ) { case label1:    code to be executed if n=label1;   break; case label2:    code to be executed if n=label2;   break; default:    code to be executed if n is different from both label1 and label2; } </li></ul>
  17. 17. PHP Switch Statement(Cont) <?php switch ($x) { case 1:   echo &quot;Number 1&quot;;   break; case 2:   echo &quot;Number 2&quot;;   break; case 3:   echo &quot;Number 3&quot;;   break; default:   echo &quot;No number between 1 and 3&quot;; } ?>
  18. 18. PHP Arrays Numeric array - An array with a numeric index. * $cars=array(&quot;Saab&quot;,&quot;Volvo&quot;,&quot;BMW&quot;,&quot;Toyota&quot;); Associative array - An array where each ID key is associated with a value * $ages = array(&quot;Peter&quot;=>32, &quot;Quagmire&quot;=>30, &quot;Joe&quot;=>34); Multidimensional array - An array containing one or more arrays. * $families = array (&quot;Griffin&quot;=>array (&quot;Peter&quot;,&quot;Lois&quot;,&quot;Megan&quot;),  &quot;Quagmire&quot;=>array(&quot;Glenn&quot;) );
  19. 19. PHP Looping - While Loops while ( condition ) { code to be executed ; } <?php $i=1; while($i<=5) {   echo &quot;The number is &quot; . $i . &quot;<br />&quot;; $i++; } ?> do   {   code to be executed;   } while ( condition ); <?php $i=1; do   {   $i++;   echo &quot;The number is &quot; . $i . &quot;<br />&quot;;   } while ($i<=5); ?>
  20. 20. PHP Looping - For Loops for ( init; condition; increment ) {    code to be executed; } <?php for ($i=1; $i<=5; $i++) {   echo &quot;The number is &quot; . $i . &quot;<br />&quot;; } ?> foreach ($ array as $ value ) {    code to be executed;  } <?php $x=array(&quot;one&quot;,&quot;two&quot;,&quot;three&quot;); foreach ($x as $value) {   echo $value . &quot;<br />&quot;; } ?>
  21. 21. PHP Functions function functionName () { code to be executed ; } <?php function writeName() { echo &quot;Kai Jim Refsnes&quot;; } echo &quot;My name is &quot;; writeName(); ?> <html> <body> <?php function &add($x,$y) { $total=$x+$y; return $total; } echo &quot;1 + 16 = &quot; . add(1,16); ?> </body> </html>
  22. 22. PHP Forms and User Input <html> <body> <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> <html> <body> Welcome <?php echo $_POST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old. </body> </html>
  23. 23. PHP $_GET Function <html> <body> <form action=&quot;welcome.php&quot; method=“get&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> <html> <body> Welcome <?php echo $_GET[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_GET[&quot;age&quot;]; ?> years old. </body> </html> http://www.dqn.vn/welcome.php?fname=Peter&age=37
  24. 24. PHP $_POST Function <html> <body> <form action=&quot;welcome.php&quot; method=“post&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> <html> <body> Welcome <?php echo $_POST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old. </body> </html> http://www.dqn.vn/welcome.php.
  25. 25. The PHP $_REQUEST Function <ul><li>The $_REQUEST function can be used to collect form data sent with both the GET and POST methods. </li></ul><ul><li>Welcome <?php echo $_REQUEST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_REQUEST[&quot;age&quot;]; ?> years old. </li></ul>
  26. 26. PHP With Database mysql_connect (&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;) or     die(&quot;Could not connect: &quot; . mysql_error()); mysql_select_db (&quot;mydb&quot;); $result =  mysql_query (&quot;SELECT id, name FROM mytable&quot;); while ($row =  mysql_fetch_array ($result)) {     printf(&quot;ID: %s  Name: %s&quot;, $row[0], $row[1]);   } mysql_free_result ($result); mysql_close() ;

×