Php Training
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Php Training

  • 7,072 views
Uploaded on

php training

php training

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
7,072
On Slideshare
7,071
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
498
Comments
0
Likes
4

Embeds 1

http://www.slideshare.net 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Web Server
    • Web server: IIS, Apache
    • Script Language: ASP, PHP..
    • Database: mysql, mssql…
  • 2. Operation Principles
  • 3. What is PHP?
    • PHP stands for P HP: H ypertext P reprocessor.
    • PHP is a server-side scripting language, like ASP
    • -PHP scripts are executed on the server
    • -PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
    • -PHP is an open source software
    • -PHP is free to download and use
  • 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 ".php", ".php3", or ".phtml“.
  • 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. LAMP
    • L : Linux(Fedora, CentOS, Debian, Ubuntu).
    • A : Apache.
    • M : Mysql.
    • P : PHP.
  • 7. PHP Syntax
    • <?php echo &quot;Hello World&quot;; ?>
    • //This is a comment
    • /* This is a comment block */
  • 8. PHP Variables
    • $var_name = value;
    • <?php $txt=&quot;Hello World!&quot;; $x=16; ?>
    • a-z, A-Z, 0-9, and _
  • 9. PHP String Variables
    • <?php $txt=&quot;Hello World&quot;; echo $txt;// Hello World ?>
    • <?php $txt1=&quot;Hello World!&quot;; $txt2=&quot;What a nice day!&quot;; echo $txt1 . &quot; &quot; . $txt2; ?>
    • <?php echo strlen(&quot;Hello world!&quot;);
    • // 12
    • ?>
    • <?php echo strpos(&quot;Hello world!&quot;,&quot;world&quot;);
    • //6 ?>
  • 10. PHP Operators -Arithmetic Operators -Assignment Operators - Comparison Operators -Logical Operators
  • 11. PHP Operators (Arithmetic)
  • 12. PHP Operators (Assignment )
  • 13. PHP Operators (Comparison)
  • 14. PHP Operators (Logical)
  • 15. PHP If...Else Statements
    • if ( condition )    code to be executed if condition is true; else    code to be executed if condition is false;
    • <?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;; ?>
  • 16. PHP Switch Statement
    • 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; }
  • 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. 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. 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. 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. 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. 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. 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. 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. The PHP $_REQUEST Function
    • The $_REQUEST function can be used to collect form data sent with both the GET and POST methods.
    • Welcome <?php echo $_REQUEST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_REQUEST[&quot;age&quot;]; ?> years old.
  • 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() ;