Professional Documents
Culture Documents
Server-side
A server is a software program, such as a web server, that runs on a remote server, reachable from a user's local computer or workstation. Server-side refers to operations that are performed by the server in a clientserver relationship in computer networking. Operations may be performed server-side because they require access to information or functionality that is not available on the client, or require typical behavior that is unreliable when it is done client-side.
Server-side Scripting
Server-side scripting is a web server technology in which a user's request is fulfilled by running a script directly on the web server to generate dynamic web pages It is usually used to provide interactive web sites that interface to databases or other data stores. Almost every major web site uses some amount of server-side scripting.
Features
Simplicity Portability Speed Open Source Extensible XML and Database Support
Continuation
MySQLs customers: Yahoo!, Google, Cisco, NASA and HP. Designed around three fundamental principles:
Speed Stability Ease
of use
Features
Speed Reliability Security Scalability Portability Ease of use Compliance with existing standards (ANSI SQL-99) Wide Application Support Free
Client
Comment Please?
In PHP, we use // to make a single-line comment or /* and */ to make a large comment block. Sample comment: <html> <body> <?php //This is a comment /* This is a comment block */ ?> </body> </html>
Variables
PHP supports a number of different variable types: integers, floating point numbers, strings and arrays It automagically determines variable type by the context in In PHP, a variable name is preceded by a dollar ($) symbol and must begin with a letter or underscore, optionally followed by more letters, numbers and/or underscores. which it is being used. Note that variable names in PHP are case sensitive, so $me is different from $Me or $ME.
Variable Demo
<html> <head></head> <body> Agent: So who do you think you are, anyhow? <br /> <?php // define variables $name = 'Neo'; $rank = 'Anomaly'; $serialNumber = 1; // print output echo "Neo: I am <b>$name</b>, the <b>$rank</b>. You can call me by my serial number, <b>$serialNumber</b>."; ?> </body> </html>
Using Operators
Arithmetic Comparison Logical String Auto-Increment and Auto-decrement
Arithmetic Operators
Assignment (=) Addition (+) Subtraction (-) Multiplication (*) Division ;returns quotient (/) Division; returns modulus (%)
Sample Code
<?php // define variables $num1 = 101; $num2 = 5; // add $sum = $num1 + $num2; // subtract $diff = $num1 - $num2;
Sample Code
// multiply $product = $num1 * $num2; // divide $quotient = $num1 / $num2; // modulus $remainder = $num1 % $num2; ?>
Tips
To perform an arithmetic operation simultaneously with an assignment, use the two operators together. The following two code snippets are equivalent: <?php $a = $a + 10; ?> <?php $a += 10; ?>
Comparison Operators
Equal to (==) Equal to and of the same type (===) Not equal to or not of the same type (!==) Not equal to (<> aka !=) Less than (<) Less than or equal to (<=) Greater than (>) Greater than or equal to (>=)
Sample Codes
<?php // define some variables $mean = 29; $median = 40; $mode = 29; // less-than operator $result = ($mean < $median);
Sample Codes
// greater-than operator $result = ($mean > $median); // less-than-or-equal-to operator $result = ($median <= $mode); // greater-than-or-equal-to operator $result = ($median >= $mode);
Sample Codes
// equality operator $result = ($mean == $mode); // not-equal-to operator $result = ($mean != $mode); // inequality operator $result = ($mean <> $mode); ?>
String Operator
String Concatenation (.) Sample Code: <?php $username = 'john'; $domain = 'example.com'; // combine them using the concatenation operator $email = $username . '@' . $domain; ?>
Tips
You can concatenate and assign simultaneously, as in the following: <?php // define string $str = 'the'; // add and assign $str .= 'n'; // $str now contains "then" ?>
Logical Operators
Logical AND (&&) Logical OR (||) Logical XOR (xor) Logical NOT (!)
Sample Codes
<?php // define some variables $user = 'joe'; $pass = 'trym3'; $saveCookie = 1; $status = 1; // logical AND $result = (($user == 'joe') && ($pass == 'trym3'));
Sample Codes
// logical OR $result = (($status < 1) || ($saveCookie == 0)); // logical NOT $result = !($saveCookie == 1); // logical XOR $result = (($status == 1) xor ($saveCookie == 1)); ?>
Sample Codes
<?php // define $total as 10 $total = 10; // increment it $total++; // $total is now 11 ?> Thus, <?php $total++; ?> is functionally equivalent to <?php $total = $total + 1; ?>. Theres also a corresponding auto-decrement operator (--), which does exactly the opposite:
Sample Codes
<?php // define $total as 10 $total = 10; // decrement it $total--; // $total is now 9 ?>
Sample Codes
<?php if ($temp >= 100) { echo 'Very hot!'; } ?>
If-else() Statement
<?php if (conditional test) { do this; } else { do this; } ?>
Sample Codes
<?php if ($temp >= 100) { echo 'Very hot!'; } else { echo 'Within tolerable limits'; } ?>
If-else-if()Statement
<?php if (conditional test #1) { do this; } elseif (conditional test #2) { do this; } else { do this; } ?>
Sample Code
<?php if ($country == 'UK') { $capital = 'London'; } elseif ($country == 'US') { $capital = 'Washington'; } else { $capital = 'Unknown'; } ?>
Switch()Statement
<?php switch (condition variable) { case possible result #1: do this; case possible result #2: do this; ... case possible result #n: do this; case default; do this; } ?>
Sample Code
<?php switch ($country) { case 'UK': $capital = 'London'; break; case 'US': $capital = 'Washington'; break; default: $capital = 'Unknown'; break; } ?>
While Loop
The first and simplest loop to learn As long as the conditional expression specified evaluates to true, the loop will continue to execute. <?php while (condition is true) { do this; } ?>
Sample Code
<?php // define number and limits for multiplication tables $num = 11; $upperLimit = 10; $lowerLimit = 1; // loop and multiply to create table while ($lowerLimit <= $upperLimit) { echo "$num x $lowerLimit = " . ($num * $lowerLimit); $lowerLimit++; } ?>
Do While Loop
You might need to execute a set of statements at least once, regardless of how the conditional expression evaluates. <?php do { do this; } while (condition is true) ?>
PHP Function
A function is simply a set of program statements that perform a specific task, and that can be called, or executed, from anywhere in your program. Syntax:
Note: Give the function a name that reflects what the function does The function name can start with a letter or underscore (not a number)
Sample Function
<?php // define a function function displayShakespeareQuote() { echo 'Some are born great, some achieve greatness, and some have greatness thrust upon them'; } // invoke a function echo Shakespeare said . displayShakespeareQuote(); ?>
List() function
The list() function is used to assign values to a list of variables in one operation. Syntax list(var1,var2...)
Explode() function
The explode() function breaks a string into an array. Splits a string into smaller components on the basis of a user-specified pattern, and then returns these elements as an array. Syntax explode(separator,string,limit)
Implode() function
The implode() function returns a string from the elements of an array. Syntax implode(separator,array) Sample: <?php $arr = array('Hello','World!','Beautiful','Day!'); echo implode(" ",$arr); ?>