2. PHP P HP:H ypertextP reprocessor PHP: Hypertext Preprocessor
PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor PHP: ...
Like GNU.
3. Its Easy but Hard
To use PHP, you must know...
HTML
SQL
CSS
JavaScript
Web Server(Apache) Configuration
Database Server(MySQL) Configuration
4. LAMP Linux/Apache/MySQL/PHP
5. Hello World!
php file.php
firefox http://localhost/file.php
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. 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. Operators
+5+2Plus
-5-2Minus
*
/
==1 == true
===1 !== true
!=
%Mod
=$a = 5
.hel . lo
etc.
9. Control Flow: if If if($name == 'Binny') { print Hi, Binny;
} elseif($name == 'Sameer') { print Hello Sameer; } else { print
Hello everybody; }
12. Functions function hello($name) { print Hello, $name.; }
hello(World);
13. OOPs and PHP
PHP 5 has all the most necessary OOPs features...
Constructors/Destructors
Visibility (public, private, protected)
Static Methods/Variables
Abstraction
Inheritance
And more...
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. Getting Help PHP Manual(CHM) Install KCHM to view it.
16. Functions
String Functions
strtolower() / strtoupper()
str_replace()
strpos()
Array Functions
array()
count()
array_push()
array_splice()
...
17. Database
MySQL must be installed and running.
Need Information about...
server(usually 'localhost')
username
password
database
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. 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. Fetching Result while($result =
mysql_fetch_assoc($sql_handle)) { print $result['name']; } Use
Database Abstraction layer!