PHP <ul><li>The easiest language to learn. </li></ul><ul><li>By Binny V A </li></ul><ul><li>http://www.bin-co.com/php/ </l...
PHP P HP:  H ypertext  P reprocessor PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor P...
Its Easy – but Hard <ul><li>To use PHP, you must know... </li></ul><ul><li>HTML </li></ul><ul><li>SQL </li></ul><ul><li>CS...
LAMP Linux/Apache/MySQL/PHP
Hello World! <ul><li><?php </li></ul><ul><li>print “Hello World”; </li></ul><ul><li>?> </li></ul><ul><li>php file.php </li...
Variables $ Prefix for variables $name =  'ILUG' ; // String $year =  2008 ; // Number $is_php_good =  true ; // Boolean /...
Arrays/Hashes $arr = array(“Indian”, “Linux”, “User”, “Group”); $arr[1] = 'Libre'; print $arr[1]; $details = array( “abbr”...
Operators <ul><li>+  5+2  Plus </li></ul><ul><li>-  5-2  Minus </li></ul><ul><li>* </li></ul><ul><li>/ </li></ul><ul><li>=...
Control Flow: if If if($name == 'Binny') { print “Hi, Binny”; } elseif($name == 'Sameer') { print “Hello Sameer”; } else {...
For/Foreach For $languages = array('PHP', 'Ruby', 'JavaScript', 'Python', 'Perl', 'Tcl'); for($i =0; $i < count($languages...
While Loop $i = 1; While($i < 10) { print $i; $i++; }
Functions function hello($name) { print “Hello, $name.”; } hello(“World”);
OOPs and PHP <ul><li>PHP 5 has all the most necessary OOPs features... </li></ul><ul><li>Constructors/Destructors </li></u...
Class class Movie { public $name; function __construct($movie_name) { $this->name = $movie_name; } function show() { print...
Getting Help PHP Manual(CHM) Install KCHM to view it.
Functions <ul><li>String Functions </li></ul><ul><li>strtolower() / strtoupper() </li></ul><ul><li>str_replace() </li></ul...
Database <ul><li>MySQL must be installed and running. </li></ul><ul><li>Need Information about... </li></ul><ul><li>server...
Connection mysql_connect('localhost', 'root', 'password'); mysql_select_db('database_name'); Use a database abstraction la...
Executing Queries  $sql_handle = mysql_query(“SELECT id,name FROM users WHERE status='1'”)  or die(mysql_error()); $result...
Fetching Result while($result = mysql_fetch_assoc($sql_handle)) { print $result['name']; } Use Database Abstraction layer!
PHP and the Web Embedding PHP... <strong><?php print hello($name) ?></strong>
Form Submission <form action=”action.php” method=”post”> Age: <input type=”text” name=”age” /> <input type=”submit” name=”...
action.php if($_POST['action'] == 'Save') { print $_POST['age']; }
Frameworks <ul><li>Zend </li></ul><ul><li>CodeIgnite </li></ul><ul><li>CakePHP </li></ul><ul><li>Symphony </li></ul><ul><l...
Free Software <ul><li>CMS Tools </li></ul><ul><ul><li>WordPress </li></ul></ul><ul><ul><li>Drupal </li></ul></ul><ul><ul><...
Credits Getting Help:  http://www.flickr.com/photos/doctorow/2496308570/ MySql:  http://www.flickr.com/photos/johnniewalke...
Upcoming SlideShare
Loading in...5
×

PHP: The easiest language to learn.

6,050

Published on

A basic introduction to PHP

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,050
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
136
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

PHP: The easiest language to learn.

  1. 1. PHP <ul><li>The easiest language to learn. </li></ul><ul><li>By Binny V A </li></ul><ul><li>http://www.bin-co.com/php/ </li></ul>
  2. 2. PHP P HP: H ypertext P reprocessor PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor PHP: ... Like GNU.
  3. 3. Its Easy – but Hard <ul><li>To use PHP, you must know... </li></ul><ul><li>HTML </li></ul><ul><li>SQL </li></ul><ul><li>CSS </li></ul><ul><li>JavaScript </li></ul><ul><li>Web Server(Apache) Configuration </li></ul><ul><li>Database Server(MySQL) Configuration </li></ul>
  4. 4. LAMP Linux/Apache/MySQL/PHP
  5. 5. Hello World! <ul><li><?php </li></ul><ul><li>print “Hello World”; </li></ul><ul><li>?> </li></ul><ul><li>php file.php </li></ul><ul><li>firefox http://localhost/file.php </li></ul>
  6. 6. Variables $ Prefix for variables $name = 'ILUG' ; // String $year = 2008 ; // Number $is_php_good = true ; // Boolean // is a comment – as is /* to */ - PHP follows the C Syntax
  7. 7. Arrays/Hashes $arr = array(“Indian”, “Linux”, “User”, “Group”); $arr[1] = 'Libre'; print $arr[1]; $details = array( “abbr” => “ILUG”, “full” => “Indian Libre User Group” ); print $details['full'];
  8. 8. Operators <ul><li>+ 5+2 Plus </li></ul><ul><li>- 5-2 Minus </li></ul><ul><li>* </li></ul><ul><li>/ </li></ul><ul><li>== 1 == true </li></ul><ul><li>=== 1 !== true </li></ul><ul><li>!= </li></ul><ul><li>% Mod </li></ul><ul><li>= $a = 5 </li></ul><ul><li>. “hel” . “lo” </li></ul><ul><li>etc. </li></ul>
  9. 9. Control Flow: if If if($name == 'Binny') { print “Hi, Binny”; } elseif($name == 'Sameer') { print “Hello Sameer”; } else { print “Hello everybody”; }
  10. 10. For/Foreach For $languages = array('PHP', 'Ruby', 'JavaScript', 'Python', 'Perl', 'Tcl'); for($i =0; $i < count($languages); $i++) { print $i+1 . “) “ . $languages[$i]; } Foreach foreach($languages as $lang) { print $lang; }
  11. 11. While Loop $i = 1; While($i < 10) { print $i; $i++; }
  12. 12. Functions function hello($name) { print “Hello, $name.”; } hello(“World”);
  13. 13. OOPs and PHP <ul><li>PHP 5 has all the most necessary OOPs features... </li></ul><ul><li>Constructors/Destructors </li></ul><ul><li>Visibility (public, private, protected) </li></ul><ul><li>Static Methods/Variables </li></ul><ul><li>Abstraction </li></ul><ul><li>Inheritance </li></ul><ul><li>And more... </li></ul>
  14. 14. Class class Movie { public $name; function __construct($movie_name) { $this->name = $movie_name; } function show() { print $this->name; } } $film = new Movie(“City of God”); $film->show();
  15. 15. Getting Help PHP Manual(CHM) Install KCHM to view it.
  16. 16. Functions <ul><li>String Functions </li></ul><ul><li>strtolower() / strtoupper() </li></ul><ul><li>str_replace() </li></ul><ul><li>strpos() </li></ul><ul><li>Array Functions </li></ul><ul><li>array() </li></ul><ul><li>count() </li></ul><ul><li>array_push() </li></ul><ul><li>array_splice() </li></ul><ul><li>... </li></ul>
  17. 17. Database <ul><li>MySQL must be installed and running. </li></ul><ul><li>Need Information about... </li></ul><ul><li>server(usually 'localhost') </li></ul><ul><li>username </li></ul><ul><li>password </li></ul><ul><li>database </li></ul>
  18. 18. Connection mysql_connect('localhost', 'root', 'password'); mysql_select_db('database_name'); Use a database abstraction layer. $db = new Sql(“localhost”, 'root', 'password', 'database_name');
  19. 19. Executing Queries $sql_handle = mysql_query(“SELECT id,name FROM users WHERE status='1'”) or die(mysql_error()); $result = mysql_fetch_assoc($sql_handle); print $result['name'];
  20. 20. Fetching Result while($result = mysql_fetch_assoc($sql_handle)) { print $result['name']; } Use Database Abstraction layer!
  21. 21. PHP and the Web Embedding PHP... <strong><?php print hello($name) ?></strong>
  22. 22. Form Submission <form action=”action.php” method=”post”> Age: <input type=”text” name=”age” /> <input type=”submit” name=”action” value=”Save” /> </form>
  23. 23. action.php if($_POST['action'] == 'Save') { print $_POST['age']; }
  24. 24. Frameworks <ul><li>Zend </li></ul><ul><li>CodeIgnite </li></ul><ul><li>CakePHP </li></ul><ul><li>Symphony </li></ul><ul><li>And more.. </li></ul>
  25. 25. Free Software <ul><li>CMS Tools </li></ul><ul><ul><li>WordPress </li></ul></ul><ul><ul><li>Drupal </li></ul></ul><ul><ul><li>Joomla/Mambo </li></ul></ul><ul><li>Forum </li></ul><ul><ul><li>phpBB </li></ul></ul><ul><ul><li>BbPress </li></ul></ul><ul><li>Shopping Cart </li></ul><ul><li>Wiki </li></ul>
  26. 26. Credits Getting Help: http://www.flickr.com/photos/doctorow/2496308570/ MySql: http://www.flickr.com/photos/johnniewalker/359440369/ Framework Image : http://www.sxc.hu/photo/916787 Free Software: http://www.flickr.com/photos/marcomolinari_it/2474783234/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×