it club @ ncp - php workshop may 10, 2011
TRANSCRIPT
AGENDA Goal
Introduction
Market Demand for PHP
PHP Language Basics
MySQL Basics Using phpMyAdmin
PHP Frameworks & Advantages
Exercise: Simple Content Management System (CMS)
2
GOAL
Not to teach advanced PHP, nor the history, just the basics to get you started
Explain code with example/practical
Not to explain what database is or SQL queries
Provide some references3
INTRODUCTION
What is PHP?PHP stands for Hypertext Preprocessor
Widely used server-side scripting language suited especially for web development
Embedded into other languages [HTML, Python]
PHP combines elements of Perl, C and Java
4
WHAT IS PHP? (CONTD..)
Source code invisible to users via ‘view source’ option from browser
Huge library of built-in functions for faster development
Compatible with all major databases
PHP is FREE5
MARKET DEMAND FOR PHP High demand and still growing
Companies get customized applications and dynamic websites
Trend is shifting towards more contractors than full time employees
Big websites using PHP : Facebook, Yahoo, Wikipedia
6
MARKET DEMAND FOR PHP (CONTD..)Reason for demand :Huge development and support community behind it
Highly maintained even though its free
Easy to learn 7
PHP BASICS Installation Separate PHP interpreter has good support in LinuxMost application requires database engineWAMP (windows, apache, mysql and php) serverLAMP (Linux, apache, mysql and php) serverXAMPP for Mac OS X, windows
8
PHP BASICS (CONTD..)Entire PHP code is contained inside
the php script tag<?php // some code here?><script language=“PHP”> … </script>PHP can be embedded into HTML code
any number of times in one page itself using php script tag
<?php statements; ?><html><?php statements; ?>
9
PHP file always have extension ‘.php’ index.php database_connection.php
PHP variables must start with a ‘$’ sign $name = ‘John Doe’; $age = 30;
PHP variables are case sensitive $Name != $name != $nAme
10
PHP BASICS (CONTD..)
Hello World Example <?php echo “Hello World!”; echo “</br>”;
echo 45; ?>
<script language=“PHP”> $city = ‘Mississauga’; echo $city; </script>
11
PHP BASICS (CONTD..)
Arithmetic Operations example <?php $x = 5; $y = 3; $a = $x + $y; //addition $s = $x - $y; //subtraction $m = $x * $y; //multiply $d = $x / $y; //division $c = $x.$y; //concatenation echo $a, $s, $m, $d, $c; ?>
12
PHP BASICS (CONTD..)
Escaping character If a string has quotation marks which is supposed to be visible then use ‘ before quotation marks to display them <?php $title = ‘ ”NCP-IT Club” ‘; echo $title; ?>
13
PHP BASICS (CONTD..)
Control structures controls the flow of execution of a program (Ex. If/else, while, for)
Example : if / else statements if ($day == “Tuesday”) { //code here
} else
{ //code here }
14
PHP CONTROL STRUCTURE
While loop
<?php $count = 0; while($count<5)
{echo “Hello”;
$count +=1;//$count++;
} ?>
15
PHP CONTROL STRUCTURE
include() include_once() require() require_once()
These files will insert or connect different files to the current file
Example: <?php include(“database.php”); ?>
16
PHP INCLUDE FILES
PHP FORM DATA Simplicity of global variables like POST and GET in php
<?php
if ($_POST["submit"])
echo "<h2>You clicked Submit!</h2>";
else if ($_POST["cancel"]) echo "<h2>You clicked Cancel!</h2>"; ?>
<form action="form.php" method="post"> <input type="submit" name="submit"
value="Submit"> <input type="submit" name="cancel"
value="Cancel"></form>
17
MYSQL - PHP MySQL is open source database
Used commercially as well
PHP works best with MySQL
Vast library of functions for PHP-MySQL
18
phpMyAdmin is free php tool to administer MySQL
Features : Intuitive web interface Manage databases, tables, views Manage MySQL users, privileges Manage MySQL triggers and
procedures Import and export data
19
MYSQL USING PHPMYADMIN
Built in functions and classes
Advanced security
Great support
Free to use
Easier to upgrade21
PHP FRAMEWORKS AND ADVANTAGES (CONTD..)
BASIC CONTENT MANAGEMENT SYSTEM (CMS)
To Do Create database Connect to database Display a form with 2-3 fields Save the form data into database
Display the saved data from database
22
TIPS AND TRICKS Do not use windows or unix
specific functions for portability
Make use of functions for repetitive code
Typos in variables will cause problem 23
REFERENCES PHP Downloads and Online
Documentationwww.php.netwww.phpmyadmin.netwww.mysql.com
Communitywww.phpbuilder.com: articles on
PHP, discussion forumswww.phpresourceindex.com
24