Php Training
Upcoming SlideShare
Loading in...5
×
 

Php Training

on

  • 6,605 views

php training

php training

Statistics

Views

Total Views
6,605
Views on SlideShare
6,604
Embed Views
1

Actions

Likes
4
Downloads
434
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Php Training Php Training Presentation Transcript

  • Web Server
    • Web server: IIS, Apache
    • Script Language: ASP, PHP..
    • Database: mysql, mssql…
  • Operation Principles
  • 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
    View slide
  • 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“. View slide
  • 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.
  • LAMP
    • L : Linux(Fedora, CentOS, Debian, Ubuntu).
    • A : Apache.
    • M : Mysql.
    • P : PHP.
  • PHP Syntax
    • <?php echo &quot;Hello World&quot;; ?>
    • //This is a comment
    • /* This is a comment block */
  • PHP Variables
    • $var_name = value;
    • <?php $txt=&quot;Hello World!&quot;; $x=16; ?>
    • a-z, A-Z, 0-9, and _
  • 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 ?>
  • PHP Operators -Arithmetic Operators -Assignment Operators - Comparison Operators -Logical Operators
  • PHP Operators (Arithmetic)
  • PHP Operators (Assignment )
  • PHP Operators (Comparison)
  • PHP Operators (Logical)
  • 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;; ?>
  • 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; }
  • 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;; } ?>
  • 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;) );
  • 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); ?>
  • 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;; } ?>
  • 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>
  • 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>
  • 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
  • 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.
  • 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.
  • 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() ;