Wednesday 3 July 2013

PHP Advance

PHP Advance
PHP provides a large number of predefined variables to any script which it runs.PHP provides an additional set of predefined arrays containing variables from the web server the environment, and user input. These new arrays are called superglobals:
All the following variables are automatically available in every scope.
PHP Superglobals:
Variable
Description
$GLOBALS
Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables.
$_SERVER
This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these. See next section for a complete list of all the SERVER variables.
$_GET
An associative array of variables passed to the current script via the HTTP GET method.
$_POST
An associative array of variables passed to the current script via the HTTP POST method.
$_FILES
An associative array of items uploaded to the current script via the HTTP POST method.
$_REQUEST
An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.
$_COOKIE
An associative array of variables passed to the current script via HTTP cookies.
$_SESSION
An associative array containing session variables available to the current script.
$_PHP_SELF
A string containing PHP script file name in which it is called.
$php_errormsg
$php_errormsg is a variable containing the text of the last error message generated by PHP.
Server variables: $_SERVER
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these.
Variable
Description
$_SERVER['PHP_SELF']
The filename of the currently executing script, relative to the document root
$_SERVER['argv']
Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.
$_SERVER['argc']
Contains the number of command line parameters passed to the script if run on the command line.
$_SERVER['GATEWAY_INTERFACE']
What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.
$_SERVER['SERVER_ADDR']
The IP address of the server under which the current script is executing.
$_SERVER['SERVER_NAME']
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
$_SERVER['SERVER_SOFTWARE']
Server identification string, given in the headers when responding to requests.
$_SERVER['SERVER_PROTOCOL']
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';
$_SERVER['REQUEST_METHOD']
Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
$_SERVER['REQUEST_TIME']
The timestamp of the start of the request. Available since PHP 5.1.0.
$_SERVER['QUERY_STRING']
The query string, if any, via which the page was accessed.
$_SERVER['DOCUMENT_ROOT']
The document root directory under which the current script is executing, as defined in the server's configuration file.
$_SERVER['HTTP_ACCEPT']
Contents of the Accept: header from the current request, if there is one.
$_SERVER['HTTP_ACCEPT_CHARSET']
Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.
$_SERVER['HTTP_ACCEPT_ENCODING']
Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.
$_SERVER['HTTP_ACCEPT_LANGUAGE']
Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.
$_SERVER['HTTP_CONNECTION']
Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.
$_SERVER['HTTP_HOST']
Contents of the Host: header from the current request, if there is one.
$_SERVER['HTTP_REFERER']
The address of the page (if any) which referred the user agent to the current page.
$_SERVER['HTTP_USER_AGENT']
This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
$_SERVER['HTTPS']
Set to a non-empty value if the script was queried through the HTTPS protocol.
$_SERVER['REMOTE_ADDR']
The IP address from which the user is viewing the current page.
$_SERVER['REMOTE_HOST']
The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.
$_SERVER['REMOTE_PORT']
The port being used on the user's machine to communicate with the web server.
$_SERVER['SCRIPT_FILENAME']
The absolute pathname of the currently executing script.
$_SERVER['SERVER_ADMIN']
The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file.
$_SERVER['SERVER_PORT']
The port on the server machine being used by the web server for communication. For default setups, this will be '80'.
$_SERVER['SERVER_SIGNATURE']
String containing the server version and virtual host name which are added to server-generated pages, if enabled.
$_SERVER['PATH_TRANSLATED']
Filesystem based path to the current script.
$_SERVER['SCRIPT_NAME']
Contains the current script's path. This is useful for pages which need to point to themselves.
$_SERVER['REQUEST_URI']
The URI which was given in order to access this page; for instance, '/index.html'.
$_SERVER['PHP_AUTH_DIGEST']
When running under Apache as module doing Digest HTTP authentication this variable is set to the 'Authorization' header sent by the client.
$_SERVER['PHP_AUTH_USER']
When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the username provided by the user.
$_SERVER['PHP_AUTH_PW']
When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the password provided by the user.
$_SERVER['AUTH_TYPE']
When running under Apache as module doing HTTP authenticated this variable is set to the authentication type.
Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality.
Using regular expression you can search a particular string inside a another string, you can replace one string by another string and you can split a string into many chunks.
PHP offers functions specific to two sets of regular expression functions, each corresponding to a certain type of regular expression. You can use any of them based on your comfort.
·         POSIX Regular Expressions
·         PERL Style Regular Expressions

POSIX Regular Expressions:

The structure of a POSIX regular expression is not dissimilar to that of a typical arithmetic expression: various elements (operators) are combined to form more complex expressions.
The simplest regular expression is one that matches a single character, such as g, inside strings such as g, haggle, or bag.
Lets give explaination for few concepts being used in POSIX regular expression. After that we will introduce you wih regular expression related functions.

Brackets

Brackets ([]) have a special meaning when used in the context of regular expressions. They are used to find a range of characters.
Expression
Description
[0-9]
It matches any decimal digit from 0 through 9.
[a-z]
It matches any character from lowercase a through lowercase z.
[A-Z]
It matches any character from uppercase A through uppercase Z.
[a-Z]
It matches any character from lowercase a through uppercase Z.
The ranges shown above are general; you could also use the range [0-3] to match any decimal digit ranging from 0 through 3, or the range [b-v] to match any lowercase character ranging from b through v.

Quantifiers:

The frequency or position of bracketed character sequences and single characters can be denoted by a special character. Each pecial character having a specific connotation. The +, *, ?, {int. range}, and $ flags all follow a character sequence.
Expression
Description
p+
It matches any string containing at least one p.
p*
It matches any string containing zero or more p's.
p?
It matches any string containing zero or more p's. This is just an alternative way to use p*.
p{N}
It matches any string containing a sequence of N p's
p{2,3}
It matches any string containing a sequence of two or three p's.
p{2, }
It matches any string containing a sequence of at least two p's.
p$
It matches any string with p at the end of it.
^p
It matches any string with p at the beginning of it.

Examples:

Following examples will clear your concepts about matching chracters.
Expression
Description
[^a-zA-Z]
It matches any string not containing any of the characters ranging from a through z and A through Z.
p.p
It matches any string containing p, followed by any character, in turn followed by another p.
^.{2}$
It matches any string containing exactly two characters.
<b>(.*)</b>
It matches any string enclosed within <b> and </b>.
p(hp)*
It matches any string containing a p followed by zero or more instances of the sequence hp.

Predefined Character Ranges

For your programming convenience several predefined character ranges, also known as character classes, are available. Character classes specify an entire range of characters, for example, the alphabet or an integer set:
Expression
Description
[[:alpha:]]
It matches any string containing alphabetic characters aA through zZ.
[[:digit:]]
It matches any string containing numerical digits 0 through 9.
[[:alnum:]]
It matches any string containing alphanumeric characters aA through zZ and 0 through 9.
[[:space:]]
It matches any string containing a space.

PHP's Regexp POSIX Functions

PHP currently offers seven functions for searching strings using POSIX-style regular expressions:
Function
Description
The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.
The ereg_replace() function searches for string specified by pattern and replaces pattern with replacement if found.
The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive.
The eregi_replace() function operates exactly like ereg_replace(), except that the search for pattern in string is not case sensitive.
The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string.
The spliti() function operates exactly in the same manner as its sibling split(), except that it is not case sensitive.
The sql_regcase() function can be thought of as a utility function, converting each character in the input parameter string into a bracketed expression containing two characters.

PERL Style Regular Expressions:

Perl-style regular expressions are similar to their POSIX counterparts. The POSIX syntax can be used almost interchangeably with the Perl-style regular expression functions. In fact, you can use any of the quantifiers introduced in the previous POSIX section.
Lets give explaination for few concepts being used in PERL regular expressions. After that we will introduce you wih regular expression related functions.

Metacharacters

A metacharacter is simply an alphabetical character preceded by a backslash that acts to give the combination a special meaning.
For instance, you can search for large money sums using the '\d' metacharacter: /([\d]+)000/, Here \d will search for any string of numerical character.
Following is the list of metacharacters which can be used in PERL Style Regular Expressions.
Character              Description
.              a single character
\s             a whitespace character (space, tab, newline)
\S             non-whitespace character
\d             a digit (0-9)
\D             a non-digit
\w             a word character (a-z, A-Z, 0-9, _)
\W             a non-word character
[aeiou]        matches a single character in the given set
[^aeiou]       matches a single character outside the given set
(foo|bar|baz)  matches any of the alternatives specified

Modifiers

Several modifiers are available that can make your work with regexps much easier, like case sensitivity, searching in multiple lines etc.
Modifier       Description
i       Makes the match case insensitive
m       Specifies that if the string has newline or carriage
        return characters, the ^ and $ operators will now
        match against a newline boundary, instead of a
        string boundary
o       Evaluates the expression only once
s       Allows use of . to match a newline character
x       Allows you to use white space in the expression for clarity
g       Globally finds all matches
cg      Allows a search to continue even after a global match fails

PHP's Regexp PERL Compatible Functions

PHP offers following functions for searching strings using Perl-compatible regular expressions:
Function
Description
The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.
The preg_match_all() function matches all occurrences of pattern in string.
The preg_replace() function operates just like ereg_replace(), except that regular expressions can be used in the pattern and replacement input parameters.
The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
The preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
Quote regular expression characters
Error handling is the process of catching errors raised by your program and then taking appropriate action. If you would handle errors properly then it may lead to many unforeseen consequences.
Its very simple in PHP to handle an errors.

Using die() function:

While wirting your PHP program you should check all possible error condition before going ahead and take appropriate action when required.
Try following example without having /tmp/test.xt file and with this file.
<?php
if(!file_exists("/tmp/test.txt"))
 {
 die("File not found");
 }
else
 {
 $file=fopen("/tmp/test.txt","r");
 print "Opend file sucessfully";
 }
 // Test of the code here.
?>
This way you can write an efficient code. Using abive technique you can stop your program whenever it errors out and display more meaningful and user friendly meassage.

Defining Custom Error Handling Function:

You can write your own function to handling any error. PHP provides you a framwork to define error handling function.
This function must be able to handle a minimum of two parameters (error level and error message) but can accept up to five parameters (optionally: file, line-number, and the error context):

Syntax

error_function(error_level,error_message, error_file,error_line,error_context);
 
Parameter
Description
error_level
Required - Specifies the error report level for the user-defined error. Must be a value number.
error_message
Required - Specifies the error message for the user-defined error
error_file
Optional - Specifies the filename in which the error occurred
error_line
Optional - Specifies the line number in which the error occurred
error_context
Optional - Specifies an array containing every variable and their values in use when the error occurred

Possible Error levels

These error report levels are the different types of error the user-defined error handler can be used for. These values cab used in combination using | operator
Value
Constant
Description
1
E_ERROR
Fatal run-time errors. Execution of the script is halted
2
E_WARNING
Non-fatal run-time errors. Execution of the script is not halted
4
E_PARSE
Compile-time parse errors. Parse errors should only be generated by the parser.
8
E_NOTICE
Run-time notices. The script found something that might be an error, but could also happen when running a script normally
16
E_CORE_ERROR
Fatal errors that occur during PHP's initial startup.
32
E_CORE_WARNING
Non-fatal run-time errors. This occurs during PHP's initial startup.
256
E_USER_ERROR
Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
512
E_USER_WARNING
Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
1024
E_USER_NOTICE
User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
2048
E_STRICT
Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
4096
E_RECOVERABLE_ERROR
Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
8191
E_ALL
All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)
All the above error level can be set using following PHP built-in library function where level cab be any of the value defined in above table.
int error_reporting ( [int $level] )
Following is the way you can create one error handling function:
<?php
function handleError($errno, $errstr,$error_file,$error_line)
{ 
 echo "<b>Error:</b> [$errno] $errstr - $error_file:$error_line";
 echo "<br />";
 echo "Terminating PHP Script";
 die();
}
?>
Once you define your custom error handler you need to set it using PHP built-in library set_error_handler function. Now lets examine our example by calling a function which does not exist.
<?php
error_reporting( E_ERROR );
function handleError($errno, $errstr,$error_file,$error_line)
{
 echo "<b>Error:</b> [$errno] $errstr - $error_file:$error_line";
 echo "<br />";
 echo "Terminating PHP Script";
 die();
}
//set error handler
set_error_handler("handleError");
 
//trigger error
myFunction();
?>

Exceptions Handling:

PHP 5 has an exception model similar to that of other programming languages. Exceptions are important and provides a better control over error handling.
Lets explain thre new keyword related to exceptions.
·         Try - A function using an exception should be in a "try" block. If the exception does not trigger, the code will continue as normal. However if the exception triggers, an exception is "thrown".
·         Throw - This is how you trigger an exception. Each "throw" must have at least one "catch".
·         Catch - - A "catch" block retrieves an exception and creates an object containing the exception information.
When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an "Uncaught Exception ...
·         An exception can be thrown, and caught ("catched") within PHP. Code may be surrounded in a try block.
·         Each try must have at least one corresponding catch block. Multiple catch blocks can be used to catch different classes of exeptions.
·         Exceptions can be thrown (or re-thrown) within a catch block.

Example:

Following is the piece of code, copy and paste this code into a file and verify the result.
<?php
try {
    $error = 'Always throw this error';
    throw new Exception($error);
 
    // Code following an exception is not executed.
    echo 'Never executed';
 
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
 
// Continue execution
echo 'Hello World';
?>
In the above example $e->getMessage function is uded to get error message. There are following functions which can be used from Exception class.
·         getMessage()- message of exception
·         getCode() - code of exception
·         getFile() - source filename
·         getLine() - source line
·         getTrace() - n array of the backtrace()
·         getTraceAsString() - formated string of trace

Creating Custom Exception Handler:

You can define your own custome excpetion handler. Use following function to set a user-defined exception handler function.
string set_exception_handler ( callback $exception_handler )
Here exception_handler is the name of the function to be called when an uncaught exception occurs. This function must be defined before calling set_exception_handler().

Example:

<?php
function exception_handler($exception) {
  echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
 
set_exception_handler('exception_handler');
 
throw new Exception('Uncaught Exception');
 
echo "Not Executed\n";
?>
Programs rarely work correctly the first time. Many things can go wrong in your program that cause the PHP interpreter to generate an error message. You have a choice about where those error messages go. The messages can be sent along with other program output to the web browser. They can also be included in the web server error log.
To make error messages display in the browser, set the display_errors configuration directive to On. To send errors to the web server error log, set log_errors to On. You can set them both to On if you want error messages in both places.
PHP defines some constants you can use to set the value of error_reporting such that only errors of certain types get reported: E_ALL (for all errors except strict notices), E_PARSE (parse errors), E_ERROR (fatal errors), E_WARNING (warnings), E_NOTICE (notices), and E_STRICT (strict notices).
While writing your PHP program, it is a good idea to use PHP-aware editors like BBEdit or Emacs. One of the speical special features of these editors is syntax highlighting. It changes the color of different parts of your program based on what those parts are. For example, strings are pink, keywords such as if and while are blue, comments are grey, and variables are black.
Another feature is quote and bracket matching, which helps to make sure that your quotes and brackets are balanced. When you type a closing delimiter such as }, the editor highlights the opening { that it matches.
There are following points which need to be verfied while debugging your program.
  • Missing Semicolons - Every PHP statement ends with a semicolon (;). PHP doesn't stop reading a statement until it reaches a semicolon. If you leave out the semicolon at the end of a line, PHP continues reading the statement on the following line.
  • Not Enough Equal Signs - When you ask whether two values are equal in a comparison statement, you need two equal signs (==). Using one equal sign is a common mistake.
  • Misspelled Variable Names - If you misspelled a variable then PHP understands it as a new variable. Remember: To PHP, $test is not the same variable as $Test.
  • Missing Dollar Signs - A missing dollar sign in a variable name is really hard to see, but at least it usually results in an error message so that you know where to look for the problem.
  • Troubling Quotes - You can have too many, too few, or the wrong kind of quotes. So check for a balanced number of quotes.
  • Missing Parentheses and curly brackets - They should always be in pairs.
  • Array Index - All the arrays should start from zero instead of 1.
Moreoever, handle all the errors properly and direct all trace messages into system log file so that if any problem happens then it will be logged into system log file and you will be able to debug that problem.

Dates are so much part of everyday life that it becomes easy to work with them without thinking. PHP also provides powerful tools for date arithmetic that make manipulating dates easy.
Getting the Time Stamp with time():
PHP's time() function gives you all the information that you need about the current date and time. It requires no arguments but returns an integer.
The integer returned by time() represents the number of seconds elapsed since midnight GMT on January 1, 1970. This moment is known as the UNIX epoch, and the number of seconds that have elapsed since then is referred to as a time stamp.
<?php
print time();
?>
It will produce following result:
948316201
This is something difficult to understand. But PHP offers excellent tools to convert a time stamp into a form that humans are comfortable with.
Converting a Time Stamp with getdate():
The function getdate() optionally accepts a time stamp and returns an associative array containing information about the date. If you omit the time stamp, it works with the current time stamp as returned by time().
Following table lists the elements contained in the array returned by getdate().
Key
Description
Example
seconds
Seconds past the minutes (0-59)
20
minutes
Minutes past the hour (0 - 59)
29
hours
Hours of the day (0 - 23)
22
mday
Day of the month (1 - 31)
11
wday
Day of the week (0 - 6)
4
mon
Month of the year (1 - 12)
7
year
Year (4 digits)
1997
yday
Day of year ( 0 - 365 )
19
weekday
Day of the week
Thursday
month
Month of the year
January
0
Timestamp
948370048
Now you have complete control over date and time. You can format this date and time in whatever format you wan.
Example:
Try out following example
<?php
$date_array = getdate();
foreach ( $date_array as $key => $val )
{
   print "$key = $val<br />";
}
$formated_date  = "Today's date: ";
$formated_date .= $date_array[mday] . "/";
$formated_date .= $date_array[mon] . "/";
$formated_date .= $date_array[year];

print $formated_date;
?>
It will produce following result:
seconds = 27
minutes = 25
hours = 11
mday = 12
wday = 6
mon = 5
year = 2007
yday = 131
weekday = Saturday
month = May
0 = 1178994327
Today's date: 12/5/2007
Converting a Time Stamp with date():
The date() function returns a formatted string representing a date. You can exercise an enormous amount of control over the format that date() returns with a string argument that you must pass to it.
date(format,timestamp)
The date() optionally accepts a time stamp if ommited then current date and time will be used. Any other data you include in the format string passed to date() will be included in the return value.
Following table lists the codes that a format string can contain:
Format
Description
Example
a
'am' or 'pm' lowercase
pm
A
'AM' or 'PM' uppercase
PM
d
Day of month, a number with leading zeroes
20
D
Day of week (three letters)
Thu
F
Month name
January
h
Hour (12-hour format - leading zeroes)
12
H
Hour (24-hour format - leading zeroes)
22
g
Hour (12-hour format - no leading zeroes)
12
G
Hour (24-hour format - no leading zeroes)
22
i
Minutes ( 0 - 59 )
23
j
Day of the month (no leading zeroes
20
l (Lower 'L')
Day of the week
Thursday
L
Leap year ('1' for yes, '0' for no)
1
m
Month of year (number - leading zeroes)
1
M
Month of year (three letters)
Jan
r
The RFC 2822 formatted date
Thu, 21 Dec 2000 16:01:07 +0200
n
Month of year (number - no leading zeroes)
2
s
Seconds of hour
20
U
Time stamp
948372444
y
Year (two digits)
06
Y
Year (four digits)
2006
z
Day of year (0 - 365)
206
Z
Offset in seconds from GMT
+5
Example:
Try out following example
<?php
print date("m/d/y G.i:s<br>", time());
print "Today is ";
print date("j of F Y, \a\\t g.i a", time());
?>
It will produce following result:
01/20/00 13.27:55
Today is 20 of January 2000, at 1.27 pm
Hope you have good understanding on how to format date and time according to your requirement. For your reference a complete list of all the date and time functions is given in PHP Date & Time Functions.
PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database.

What you should already have ?

·         You have gone through MySQL tutorial to understand MySQL Basics.
·         Downloaded and installed a latest version of MySQL.
·         Created database user guest with password guest123.
·         If you have not created a database then you would need root user and its password to create a database.
We have divided this chapter in the following sections:
1.      Connecting to MySQL database - Learn how to use PHP to open and close a MySQL database connection.
2.      Create MySQL Database Using PHP - This part explains how to create MySQL database and tables using PHP.
3.      Delete MySQL Database Using PHP - This part explains how to delete MySQL database and tables using PHP.
4.      Insert Data To MySQL Database - Once you have created your database and tables then you would like to insert your data into created tables. This session will take you through real example on data insert.
5.      Retrevieng Data From MySQL Database - Learn how to fetch records from MySQL database using PHP.
6.      Using Paging through PHP - This one explains how to show your query result into multiple pages and how to create the navigation link.
7.      Updating Data Into MySQL Database - This part explains how to update existing records into MySQL database using PHP.
8.      Deleting Data From MySQL Database - This part explains how to delete or purge existing records from MySQL database using PHP.
9.      Using PHP To Backup MySQL Database - Learn different ways to take backup of your MySQL database for safety purpose.
What is AJAX ?
  • AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS and Java Script.
  • Conventional web application trasmit information to and from the sever using synchronous requests. This means you fill out a form, hit submit, and get directed to a new page with new information from the server.
  • With AJAX when submit is pressed, JavaScript will make a request to the server, interpret the results and update the current screen. In the purest sense, the user would never know that anything was even transmitted to the server.
For complete learning on AJAX, please refer to AJAX Tutorial.
PHP and AJAX Example:
To clearly illustrate how easy it is to access information from a database using Ajax and PHP, we are going to build MySQL queries on the fly and display the results on "ajax.html". But before we proceed, lets do ground work. Create a table using the following command.
NOTE: We are asuing you have sufficient privilege to perform following MySQL operations
CREATE TABLE `ajax_example` (
  `name` varchar(50) NOT NULL,
  `age` int(11) NOT NULL,
  `sex` varchar(1) NOT NULL,
  `wpm` int(11) NOT NULL,
  PRIMARY KEY  (`name`)
)
Now dump the following data into this table using the foloowing SQL statements
INSERT INTO `ajax_example` VALUES ('Jerry', 120, 'm', 20);
INSERT INTO `ajax_example` VALUES ('Regis', 75, 'm', 44);
INSERT INTO `ajax_example` VALUES ('Frank', 45, 'm', 87);
INSERT INTO `ajax_example` VALUES ('Jill', 22, 'f', 72);
INSERT INTO `ajax_example` VALUES ('Tracy', 27, 'f', 0);
INSERT INTO `ajax_example` VALUES ('Julie', 35, 'f', 90);

Client Side HTML file
Now lets have our client side HTML file which is ajax.html and it will have following code
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
 var ajaxRequest;  // The variable that makes Ajax possible!
       
 try{
   // Opera 8.0+, Firefox, Safari
   ajaxRequest = new XMLHttpRequest();
 }catch (e){
   // Internet Explorer Browsers
   try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
   }catch (e) {
      try{
         ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
         // Something went wrong
         alert("Your browser broke!");
         return false;
      }
   }
 }
 // Create a function that will receive data
 // sent from the server and will update
 // div section in the same page.
 ajaxRequest.onreadystatechange = function(){
   if(ajaxRequest.readyState == 4){
      var ajaxDisplay = document.getElementById('ajaxDiv');
      ajaxDisplay.innerHTML = ajaxRequest.responseText;
   }
 }
 // Now get the value from user and pass it to
 // server script.
 var age = document.getElementById('age').value;
 var wpm = document.getElementById('wpm').value;
 var sex = document.getElementById('sex').value;
 var queryString = "?age=" + age ;
 queryString +=  "&wpm=" + wpm + "&sex=" + sex;
 ajaxRequest.open("GET", "ajax-example.php" +
                              queryString, true);
 ajaxRequest.send(null);
}
//-->
</script>
<form name='myForm'>
Max Age: <input type='text' id='age' /> <br />
Max WPM: <input type='text' id='wpm' />
<br />
Sex: <select id='sex'>
<option value="m">m</option>
<option value="f">f</option>
</select>
<input type='button' onclick='ajaxFunction()'
                              value='Query MySQL'/>
</form>
<div id='ajaxDiv'>Your result will display here</div>
</body>
</html>
NOTE: The way of passing variables in the Query is according to HTTP standard and the have formA
URL?variable1=value1;&variable2=value2;
Now the above code will give you a screen as given below

NOTE: This is dummy screen and would not work
Top of Form
Max Age: 

Max WPM:

Sex:
Bottom of Form
Your result will display here

Server Side PHP file
So now your client side script is ready. Now we have to write our server side script which will fetch age, wpm and sex from the database and will send it back to the client. Put the following code into "ajax-example.php" file
<?php
$dbhost = "localhost";
$dbuser = "dbusername";
$dbpass = "dbpassword";
$dbname = "dbname";
        //Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
        //Select Database
mysql_select_db($dbname) or die(mysql_error());
        // Retrieve data from Query String
$age = $_GET['age'];
$sex = $_GET['sex'];
$wpm = $_GET['wpm'];
        // Escape User Input to help prevent SQL Injection
$age = mysql_real_escape_string($age);
$sex = mysql_real_escape_string($sex);
$wpm = mysql_real_escape_string($wpm);
        //build query
$query = "SELECT * FROM ajax_example WHERE sex = '$sex'";
if(is_numeric($age))
        $query .= " AND age <= $age";
if(is_numeric($wpm))
        $query .= " AND wpm <= $wpm";
        //Execute query
$qry_result = mysql_query($query) or die(mysql_error());

        //Build Result String
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Name</th>";
$display_string .= "<th>Age</th>";
$display_string .= "<th>Sex</th>";
$display_string .= "<th>WPM</th>";
$display_string .= "</tr>";

// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
        $display_string .= "<tr>";
        $display_string .= "<td>$row[name]</td>";
        $display_string .= "<td>$row[age]</td>";
        $display_string .= "<td>$row[sex]</td>";
        $display_string .= "<td>$row[wpm]</td>";
        $display_string .= "</tr>";
       
}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;
?>

Now try by entering a valid value in "Max Age" or any other box and then click Query MySQL button.
Top of Form
Max Age: 

Max WPM:

Sex:
Bottom of Form
Your result will display here

If you have successfully completed this lesson then you know how to use MySQL, PHP, HTML, and Javascript in tandem to write Ajax applications.
XML is a markup language that looks a lot like HTML. An XML document is plain text and contains tags delimited by < and >.There are two big differences between XML and HTML:
·         XML doesn't define a specific set of tags you must use.
·         XML is extremely picky about document structure.
XML gives you a lot more freedom than HTML. HTML has a certain set of tags: the <a></a> tags surround a link, the <p> startsa paragraph and so on. An XML document, however, can use any tags you want. Put <rating></rating> tags around a movie rating, >height></height> tags around someone's height. Thus XML gives you option to device your own tags.
XML is very strict when it comes to document structure. HTML lets you play fast and loose with some opening and closing tags. BUt this is not the case with XML.

HTML list that's not valid XML:

<ul>
<li>Braised Sea Cucumber
<li>Baked Giblets with Salt
<li>Abalone with Marrow and Duck Feet
</ul>
This is not a valid XML document because there are no closing </li> tags to match up with the three opening <li> tags. Every opened tag in an XML document must be closed.

HTML list that is valid XML:

<ul>
<li>Braised Sea Cucumber</li>
<li>Baked Giblets with Salt</li>
<li>Abalone with Marrow and Duck Feet</li>
</ul>

Parsing an XML Document:

PHP 5's new SimpleXML module makes parsing an XML document, well, simple. It turns an XML document into an object that provides structured access to the XML.
To create a SimpleXML object from an XML document stored in a string, pass the string to simplexml_load_string( ). It returns a SimpleXML object.

Example:

Try out following example:
<?php
 
$channel =<<<_XML_
<channel>
<title>What's For Dinner<title>
<link>http://menu.example.com/<link>
<description>Choose what to eat tonight.</description>
</channel>
_XML_;
 
$xml = simplexml_load_string($channel);
print "The $xml->title channel is available at $xml->link. ";
print "The description is \"$xml->description\"";
?>
It will produce following result:
The What's For Dinner channel is available at http://menu.example.com/. The description is "Choose what to eat tonight."
NOTE: You can use function simplexml_load_file( filename) if you have XML content in a file.
For a complete detail of XML parsing function check PHP Function Reference.

Generating an XML Document:

SimpleXML is good for parsing existing XML documents, but you can't use it to create a new one from scratch.
The easiest way to generate an XML document is to build a PHP array whose structure mirrors that of the XML document and then to iterate through the array, printing each element with appropriate formatting.

Example:

Try out following example:
<?php
 
$channel = array('title' => "What's For Dinner",
                 'link' => 'http://menu.example.com/',
                 'description' => 'Choose what to eat tonight.');
print "<channel>\n";
foreach ($channel as $element => $content) {
   print " <$element>";
   print htmlentities($content);
   print "</$element>\n";
}
print "</channel>";
?>
It will produce following result:
<channel>
<title>What's For Dinner</title>
<link>http://menu.example.com/</link>
<description>Choose what to eat tonight.</description>
</channel></html>
We can imagine our universe made of different objects like sun, earth, moon etc. Similarly we can imagine our car made of different objects like wheel, steering, gear etc. Same way there is object oriented programming concepts which assume everything as an object and implement a software using different objects.

Object Oriented Concepts:

Before we go in detail, lets define important terms related to Object Oriented Programming.
·         Class: This is a programmer-defined datatype, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.
·         Object: An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.
·         Member Variable: These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.
·         Member function: These are the function defined inside a class and are used to access object data.
·         Inheritance: When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.
·         Parent class: A class that is inherited from by another class. This is also called a base class or super class.
·         Child Class: A class that inherits from another class. This is also called a subclass or derived class.
·         Polymorphism: This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it make take different number of arguments and can do different task.
·         Overloading: a type of polymorphism in which some or all of operators have different implementations depending on the types of their arguments. Similarly functions can also be overloaded with different implementation.
·         Data Abstraction: Any representation of data in which the implementation details are hidden (abstracted).
·         Encapsulation: refers to a concept where we encapsulate all the data and member functions together to form an object.
·         Constructor: refers to a special type of function which will be called automatically whenever there is an object formation from a class.
·         Destructors: refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.

Defining PHP Classes:

The general form for defining a new class in PHP is as follows:
<?php
class phpClass{
   var $var1;
   var $var2 = "constant string";
   function myfunc ($arg1, $arg2) {
      [..]
   }
   [..]
}
?>
Here is the description of each line:
·         The special form class, followed by the name of the class that you want to define.
·         A set of braces enclosing any number of variable declarations and function definitions.
·         Variable declarations start with the special form var, which is followed by a conventional $ variable name; they may also have an initial assignment to a constant value.
·         Function definitions look much like standalone PHP functions but are local to the class and will be used to set and access object data.

Example:

Here is an example which defines a class of Books type:
<?php
class  Books{
    /* Member variables */
    var $price;
    var $title;
    /* Member functions */
    function setPrice($par){
       $this->price = $var;
    }
    function getPrice(){
       echo $this->price ."<br/>";
    }
    function setTitle($par){
       $this->title = $par;
    }
    function getTitle(){
       echo $this->title ." <br/>";
    }
}
?>
The variable $this is a special variable and it refers to the same object ie. itself.

Creating Objects in PHP

Once you defined your class, then you can create as many objects as you like of that class type. Following is an example of how to create object using new operator.
   $physics = new Books;
   $maths = new Books;
   $chemistry = new Books;
Here we have created three objects and these objects are independent of each other and they will have their existance separately. Next we will see how to access member function and process member variables.

Calling Member Functions

After creating your objects, you will be able to call member functions related to that object. One member function will be able to process member variable of related object only.
Following example shows how to set title and prices for the three books by calling member functions.
   $physics->setTitle( "Physics for High School" );
   $chemistry->setTitle( "Advanced Chemistry" );
   $maths->setTitle( "Algebra" );
 
   $physics->setPrice( 10 );
   $chemistry->setPrice( 15 );
   $maths->setPrice( 7 );
Now you call another member functions to get the values set by in above example:
   $physics->getTitle();
   $chemistry->getTitle();
   $maths->getTitle();
   $physics->getPrice();
   $chemistry->getPrice();
   $maths->getPrice();
This will produce follwoing result:
  Physics for High School
  Advanced Chemistry
  Algebra
  10
  15
  7

Constructor Functions:

Constructor Functions are special type of functions which are called automatically whenever an object is created. So we take full advantage of this behaviour, by initializing many things through constructor functions.
PHP provides a special function called __construct() to define a constructor. You can pass as many as arguments you like into the constructor function.
Following example will create one constructor for Books class and it will initialize price and title for the book at the time of object creation.
function __construct( $par1, $par2 ){
   $this->price = $par1;
   $this->title = $par2;
}
Now we don't need to call set function separately to set price and title. We can initialize these two member variables at the time of object creation only. Check following example below:
   $physics = new Books( "Physics for High School", 10 );
   $maths = new Books ( "Advanced Chemistry", 15 );
   $chemistry = new Books ("Algebra", 7 );
 
   /* Get those set values */
   $physics->getTitle();
   $chemistry->getTitle();
   $maths->getTitle();
 
   $physics->getPrice();
   $chemistry->getPrice();
   $maths->getPrice();
This will produce following result:
  Physics for High School
  Advanced Chemistry
  Algebra
  10
  15
  7

Destructor:

Like a constructor function you can define a destructor function using function __destruct(). You can release all the resourceses with-in a destructor.

Inheritance:

PHP class definitions can optionally inherit from a parent class definition by using the extends clause. The syntax is as follows:
  class Child extends Parent {
     <definition body>
  }
The effect of inheritance is that the child class (or subclass or derived class) has the following characteristics:
·         Automatically has all the member variable declarations of the parent class.
·         Automatically has all the same member functions as the parent, which (by default) will work the same way as those functions do in the parent.
Following example inherit Books class and adds more functionality based on the requirement.
class Novel extends Books{
   var publisher;
   function setPublisher($par){
     $this->publisher = $par;
   }
   function getPublisher(){
     echo $this->publisher. "<br />";
   }
}
Now apart from inherited functions, class Novel keeps two additional member functions.

Function Overriding:

Function definitions in child classes override definitions with the same name in parent classes. In a child class, we can modify the definition of a function inherited from parent class.
In the follwoing example getPrice and getTitle functions are overriden to retrun some values.
    function getPrice(){
       echo $this->price . "<br/>";
       return $this->price;
    }
    function getTitle(){
       echo $this->title . "<br/>";
       return $this->title;
    }

Public Members:

Unless you specify otherwise, properties and methods of a class are public. That is to say, they may be accessed in three possible situations:
·         From outside the class in which it is declared
·         From within the class in which it is declared
·         From within another class that implements the class in which it is declared
Till now we have seen all members as public members. If you wish to limit the accessibility of the members of a class then you define class members as private or protected.

Private members:

By designating a member private, you limit its accessibility to the class in which it is declared. The private member cannot be referred to from classes that inherit the class in which it is declared and cannot be accessed from outside the class.
A class member can be made private by using private keyword infront of the member.
class MyClass {
   private $car = "skoda";
   $driver = "SRK";
 
   function __construct($par) {
      // Statements here run every time
      // an instance of the class
      // is created.
   }
   function myPublicFunction() {
      return("I'm visible!");
   }
   private function myPrivateFunction() {
      return("I'm  not visible outside!");
   }
}
When MyClass class is inherited by another class using extends, myPublicFunction() will be visible, as will $driver. The extending class will not have any awareness of or access to myPrivateFunction and $car, because they are declared private.

Protected members:

A protected property or method is accessible in the class in which it is declared, as well as in classes that extend that class. Protected members are not available outside of those two kinds of classes. A class member can be made protected by using protected keyword infront of the member.
Here is different version of MyClass:
class MyClass {
   protected $car = "skoda";
   $driver = "SRK";
 
   function __construct($par) {
      // Statements here run every time
      // an instance of the class
      // is created.
   }
   function myPublicFunction() {
      return("I'm visible!");
   }
   protected function myPrivateFunction() {
      return("I'm  visible in child class!");
   }
}

Interfaces:

Interfaces are defined to provide a common function names to the implementors. Different implementors can implement those interfaces according to theri requirements. You can say, interfaces are skeltons which are implemented by developers.
As of PHP5, it is possible to define an interface, like this:
interface Mail {
   public function sendMail();
}
Then, if another class implemented that interface, like this:
class Report implements Mail {
   // sendMail() Definition goes here
}

Constants:

A constant is somewhat like a variable, in that it holds a value, but is really more like a function because a constant is immutable. Once you declare a constant, it does not change.
Declaring one constant is easy, as is done in this version of MyClass:
class MyClass {
   const requiredMargin = 1.7;
   function __construct($incomingValue) {
      // Statements here run every time
      // an instance of the class
      // is created.
   }
}
In this class, requiredMargin is a constant. It is declared with the keyword const, and under no circumstances can it be changed to anything other than 1.7. Note that the constant's name does not have a leading $, as variable names do.

Abstract Classes:

An abstract class is one that cannot be instantiated, only inherited. You declare an abstract class with the keyword abstract, like this:
When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child; additionally, these methods must be defined with the same visibillity.
abstract class MyAbstractClass {
   abstract function myAbstractFunction() {
   }
}
Note that function definitions inside an abstract class must also be preceded by the keyword abstract. It is not legal to have abstract function definitions inside a non-abstract class.

Static Keyword:

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).
Try out following example:
<?php
class Foo
{
    public static $my_static = 'foo';
 
    public function staticValue() {
        return self::$my_static;
    }
}
print Foo::$my_static . "\n";
$foo = new Foo();
print $foo->staticValue() . "\n";

Final Keyword:

PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.
Following example results in Fatal error: Cannot override final method BaseClass::moreTesting()
<?php
class BaseClass {
   public function test() {
       echo "BaseClass::test() called<br>";
   }
  
   final public function moreTesting() {
       echo "BaseClass::moreTesting() called<br>";
   }
}
 
class ChildClass extends BaseClass {
   public function moreTesting() {
       echo "ChildClass::moreTesting() called<br>";
   }
}
?>

Calling parent constructors:

Instead of writing an entirely new constructor for the subclass, let's write it by calling the parent's constructor explicitly and then doing whatever is necessary in addition for instantiation of the subclass. Here's a simple example:
class Name
{
   var $_firstName;
   var $_lastName;
   function Name($first_name, $last_name)
   {
     $this->_firstName = $first_name;
     $this->_lastName = $last_name;
   }
   function toString() {
     return($this->_lastName .", " .$this->_firstName);
   }
}
class NameSub1 extends Name
{
   var $_middleInitial;
   function NameSub1($first_name, $middle_initial, $last_name) {
       Name::Name($first_name, $last_name);
       $this->_middleInitial = $middle_initial;
   }
   function toString() {
       return(Name::toString() . " " . $this->_middleInitial);
   }
}
In this example, we have a parent class (Name), which has a two-argument constructor, and a subclass (NameSub1), which has a three-argument constructor. The constructor of NameSub1 functions by calling its parent constructor explicitly using the :: syntax (passing two of its arguments along) and then setting an additional field. Similarly, NameSub1 defines its nonconstructor toString() function in terms of the parent function that it overrides.
NOTE: A constructor can be defined with the same name as the name of a class. It is defined in above example.
The simplest way to think of PHP is as interpreted C that you can embed in HTML documents. The language itself is a lot like C, except with untyped variables, a whole lot of Web-specific libraries built in, and everything hooked up directly to your favorite Web server.
The syntax of statements and function definitions should be familiar, except that variables are always preceded by $, and functions do not require separate prototypes.
Here we will put some similarities and diferences in PHP and C

Similarities:

·         Syntax: Broadly speaking, PHP syntax is the same as in C: Code is blank insensitive, statements are terminated with semicolons, function calls have the same structure (my_function(expression1, expression2)), and curly braces ({ and }) make statements into blocks. PHP supports C and C++-style comments (/* */ as well as //), and also Perl and shell-script style (#).
·         Operators: The assignment operators (=, +=, *=, and so on), the Boolean operators (&&, ||, !), the comparison operators (<,>, <=, >=, ==, !=), and the basic arithmetic operators (+, -, *, /, %) all behave in PHP as they do in C.
·         Control structures: The basic control structures (if, switch, while, for) behave as they do in C, including supporting break and continue. One notable difference is that switch in PHP can accept strings as case identifiers.
·         Function names: As you peruse the documentation, you.ll see many function names that seem identical to C functions.

Differences:

·         Dollar signs: All variables are denoted with a leading $. Variables do not need to be declared in advance of assignment, and they have no intrinsic type.
·         Types: PHP has only two numerical types: integer (corresponding to a long in C) and double (corresponding to a double in C). Strings are of arbitrary length. There is no separate character type.
·         Type conversion: Types are not checked at compile time, and type errors do not typically occur at runtime either. Instead, variables and values are automatically converted across types as needed.
·         Arrays: Arrays have a syntax superficially similar to C's array syntax, but they are implemented completely differently. They are actually associative arrays or hashes, and the index can be either a number or a string. They do not need to be declared or allocated in advance.
·         No structure type: There is no struct in PHP, partly because the array and object types together make it unnecessary. The elements of a PHP array need not be of a consistent type.
·         No pointers: There are no pointers available in PHP, although the typeless variables play a similar role. PHP does support variable references. You can also emulate function pointers to some extent, in that function names can be stored in variables and called by using the variable rather than a literal name.
·         No prototypes: Functions do not need to be declared before their implementation is defined, as long as the function definition can be found somewhere in the current code file or included files.
·         Memory management: The PHP engine is effectively a garbage-collected environment (reference-counted), and in small scripts there is no need to do any deallocation. You should freely allocate new structures - such as new strings and object instances. IN PHP5, it is possible to define destructors for objects, but there is no free or delete. Destructors are called when the last reference to an object goes away, before the memory is reclaimed.
·         Compilation and linking: There is no separate compilation step for PHP scripts.
·         Permissiveness: As a general matter, PHP is more forgiving than C (especially in its type system) and so will let you get away with new kinds of mistakes. Unexpected results are more common than errors.
This chapter will list out major similarities and differences in between PHP and PERL. This will help PERL developers to understand PHP very quickly and avoid common mistakes.

Similarities:

·         Compiled scripting languages: Both Perl and PHP are scripting languages.This means that they are not used to produce native standalone executables in advance of execution.
·         Syntax: PHP's basic syntax is very close to Perl's, and both share a lot of syntactic features with C. Code is insensitive to whitespace, statements are terminated by semicolons, and curly braces organize multiple statements into a single block. Function calls start with the name of the function, followed by the actual arguments enclosed in parentheses and separated by commas.
·         Dollar-sign variables: All variables in PHP look like scalar variables in Perl: a name with a dollar sign ($) in front of it.
·         No declaration of variables: As in Perl, you don.t need to declare the type of a PHP variable before using it.
·         Loose typing of variables: As in Perl, variables in PHP have no intrinsic type other than the value they currently hold. You can store iether number or string in same type of variable.
·         Strings and variable interpolation: Both PHP and Perl do more interpretation of double-quoted strings ("string") than of singlequoted strings ('string').

Differences:

·         PHP is HTML-embedded: Although it is possible to use PHP for arbitrary tasks by running it from the command line, it is more typically connected to a Web server and used for producing Web pages. If you are used to writing CGI scripts in Perl, the main difference in PHP is that you no longer need to explicitly print large blocks of static HTML using print or heredoc statements and instead can simply write the HTML itself outside of the PHP code block.
·         No @ or % variables: PHP has one only kind of variable, which starts with a dollar sign ($). Any of the datatypes in the language can be stored in such variables, whether scalar or compound.
·         Arrays versus hashes: PHP has a single datatype called an array that plays the role of both hashes and arrays/lists in Perl.
·         Specifying arguments to functions: Function calls in PHP look pretty much like subroutine calls in Perl. Function definitions in PHP, on the other hand, typically require some kind of list of formal arguments as in C or Java which is not the csse in PERL.
·         Variable scoping in functions: In Perl, the default scope for variables is global. This means that top-level variables are visible inside subroutines. Often, this leads to promiscuous use of globals across functions. In PHP, the scope of variables within function definitions is local by default.
·         No module system as such: In PHP there is no real distinction between normal code files and code files used as imported libraries.
·         Break and continue rather than next and last: PHP is more like C langauge and uses break and continue instead of next and last statement.
·         No elsif: A minor spelling difference: Perl's elsif is PHP's elseif.
·         More kinds of comments: In addition to Perl-style (#) single-line comments, PHP offers C-style multiline comments (/* comment */ ) and Java-style single-line comments (// comment).
·         Regular expressions: PHP does not have a built-in syntax specific to regular expressions, but has most of the same functionality in its "Perl-compatible" regular expression functions.


No comments:

Post a Comment

Featured post

Life Infotech now a leading brand in the field of technology training

  Life Infotech now a leading brand in the field of technology training & its invites students around the nation to be a part of the Tra...