PASTE NAVIGATION MENU CODE

Sunday 25 March 2012

PHP

| | with 0 comments |

Introduction

PHP (PHP: Hypertext Processor) is a server-side scripting language created by an open-source community and managed by the PHP Group. PHP is a server-side scripting language, which can receive standard input from a web browser and output standard plain-text output such as HTML. As a scripting language, PHP was one of the first server-side scripting languages which could be embedded inside an HTML document.
PHP powers several large-scale websites such as Facebook, Yahoo!, YouTube, Wikipedia and more. Features of the langauge which make it so popular include its free and open-source license, quick integration with popular databases such as MySQL, support by almost all hosting providers and a committed development community.

Structure of the langauge

PHP is a loosely typed language, meaning the type of a variable does not need to be declared before it is used. Also, variable names must be preceded by a dollar sign ($). For example
$myvariable = 7;
$myvariable = "hello";
When embedded inside other documents such as HTML pages, PHP code must be placed within tags, such as:
<?php
//code goes here
?>
As of PHP 5, Object-Oriented support has been added to the langauge.
<?php
class Dog 
{
 //Attribute
 public $breed = "Labrador";

 //Operation
 public function bark() {
  echo "Woof!";
 } 
}
?>
Other features which make PHP popular include inline string parsing:
$myname = "Rasmus";

echo "Hello $myname, have a nice day!";

LAMP

One popular architecture for the use of PHP is a LAMP (Linux, Apache, MySQL, PHP) server. A LAMP server is based on technologies which are both free and open-source, reducing costs for the web developer. Mac OS X and Windows users have applications called MAMP and WAMP respectively, which can automatically set up an Apache/MySQL/PHP environment on the target operating system, as well as helper utilities such as phpMyAdmin, a php-based MySQL front-end. Connecting to a MySQL database and executing a query in PHP is trivial.
//Connect to database
$con = mysql_connect("localhost","peter","abc123") or die(mysql_error());
 
//Select the database to work with
mysql_select_db("student", $con);

//SQL query 
$query = "SELECT name,surname FROM student WHERE country = 'Greenland'"; 

$result = mysql_query($query, $con); //Execute query
$row = mysql_fetch_assoc($result); //Fetch first row from results

Frameworks

Several Rapid Application Development (RAD) frameworks are available to speed up PHP development. These include frameworks such as Zend, CakePHP, Symfony and more. Besides offering speed and thousands of pre-built classes, many frameworks enforce the Model-View-Controller (MVC) approach, for more reusable code.

Post a Comment

Please enter your comments here..

0 comments: