PHP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21
At a glance
Powered by AI
The document discusses PHP and MySQL training conducted at Allsoft Solutions. It covers topics like the company profile, HTML, PHP features, and PHPMyAdmin.

PHP is a server-side scripting language used for web development. Its key features include being simple, secure, portable, robust and open source.

PHPMyAdmin is a free tool to manage MySQL databases via the web. It allows performing operations like managing databases, tables and fields through an intuitive interface.

PHP/MYSQL

A
SUMMER TRAINING REPORT

FOR THE PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE AWARD


OF DEGREE OF BACHELOR OF TECHNOLOGY

AFFLIATED TO

KURUKSHETRA UNIVERISTY, KURUKSHETRA

SUBMITTED BY
PRARTHANA WAHI

(2308015)

UNDER THE SUPERIVISION OF

Mr. PANKAJ CHOPRA

PRESIDENT

ALLSOFT SOLUTIONS. Inc

FROM 3RD JULY 2010 TO 10TH AUGUST 2010

DEPARTMENT OF COMPUTER ENGINEERING

AMBALA COLLEGE OF ENGINEERING AND APPLIED RESEARCH


DEVSTHALI, NEAR MITHAPUR, AMBALA

HARYANA, INDIA

DECEMBER 2010

1
ACKNOWLEDGMENT
The first and foremost to influence and direct the course of my studies has been Mr. Pankaj under whose
supervision I have been able to accomplish my project on time. I would also like to thank him for his ample
guidance and support. I am immensely grateful to him for the inspiration, able guidance, and valuable
suggestion at every stage of work.

I am indebted to Mr. Arvind Selwal, the HOD, Computer Science division & other faculty members helpful to
me in getting this mighty task of training completed to a successful end. If not for the above mentioned
people my training would never have been completed successfully.
I once again extend my sincere thanks to all of them.

PRARTHANA WAHI

2
COMPANY PROFILE

Founded in 2000, Allsoft Solutions, Inc. corporate headquarters in Philadelphia with Offices in California and
India. It is a software consulting and development firm specializing in variety of technologies. Allsoft
Solutions has over 8 years of working experience on various IBM, Oracle, and Open Source technologies such
as PHP/MYMYSQL. It leverages expertise of its IT professionals by providing various training courses in
North India. The IBM Career Education in IBM Software (CEIS) program is the ideal educational solution to
prepare fresh graduates and career professionals for growing information technology demands, helping them
to acquire the right set of skills, education and experience to build successful careers in this industry.
Allsoft Solutions, Inc. is a software consulting and development firm specializing in variety of technologies.
We blend creative, strategic planning with expert knowledge to tackle the toughest challenges for businesses.
Our goal is to achieve 100% client satisfaction by economically delivering ideal solutions tailored for each
client.
Allsoft Solutions has over 8 years of working experience on various IBM, Oracle, Open Source
technologies(PHP/MYSQL). They leverage expertise of their IT professionals by providing various training
courses in North India. The IBM Career Education in IBM Software (CEIS) program is the ideal educational
solution to prepare fresh graduates and career professionals for growing information technology demands,
helping them to acquire the right set of skills, education and experience to build successful careers in this
industry.

The curriculum offers a "blended learning" approach by integrating classroom, hands-on lab exercises and
team projects, giving students theoretical as well as practical training to build strong database administration,
websphere, application development and testing skills. The trainings are provided by Industry experienced
professionals. At Allsoft, emphasis is placed on helping you begin to develop skills and knowledge in the
areas that can have practical value in the workplace. Besides technical instructions, the programs offered at
Allsoft focus on helping you develop problem solving, critical thinking, communication and teamwork skills.

3
HTML

HTML stands for Hypertext Markup Language, which is the main programming structure for web pages
and browser software. When browser software accesses an HTML file it understands how to parse the
document according to the file's extension.(.html - .txt - .php - .xml - .pdf - .doc - etc... ). HTML provides us a
means of laying out and structuring our web pages using paragraphs, images, lists, indents, boxes, tables,
colors, padding, and many more data structuring methods common to most data processing systems.

When a browser reads an HTML document it interprets exactly how to render it from the HTML tags and
elements laid out in it. An HTML document is just a fancy text(.txt) file, given a diffrerent extension(.html) so
browser software can communicate with it the way it needs to.

HTML documents are structured specifically for communicating with browser software, so there are also
things at play in the background processes if we require them. There are different distinct sections of an
HTML web page which allow it to communicate with the correct processes. For instance, browser software
knows to display or render everything within the <body></body> section of a web page. There is also
a <head></head> section in a proper HTML web page that is used for communicating privately to the
browser software, and not the person viewing your page.

HTML Documents = Web Pages

 HTML documents describe web pages


 HTML documents contain HTML tags and plain text
 HTML documents are also called web pages

The Main Elements of an HTML Document

Element Element Function


<DOCTYPE> Communicates with software(validators, browser) accessing the page to help identify the
HTML rules being followed inside the document. It states and helps verify that all tags used
within the document are syntactically correct to the document type defined.
<html> Defines the beginning and end of an HTML document. It contains the <head>, <meta>,
<title>, and <body> sections of the document. Think of it as your document container.
<head> Used to describe or modify the content in the document. The head element contains the
<meta>, and <title> elements. We also use this section to include CSS, Javascript, and much
more into our documents before the content of the <body> element is displayed.
<meta> Used to describe the document with a description and keywords primarily. We can also
communicate with search engine robots using many types of meta type content, and give
specific instructions to the browser software currently accessing our pages.
<title> Displays a page title in the browser tab bars and bookmark lists. The title element should
come directly after your <meta> tags in the document and also communicates to search
engine indexing bots to some degree.
<body> Directly after the <head> element closes(</head>) we define our <body> element. This
element contains everything that we want to display to the browser software. The body
element can have attributes set in it to affect the entire document if the author so chooses.

4
CSS: Cascading Style Sheets

CSS is an acronym for Cascading Style Sheets. CSS is used to separate presentation and style from document
markup content. It works by targeting your web page elements. CSS can target and style native elements like
your body tag or all <p> tags on the page. It can also be made to target specific individual page elements or a
group of labeled elements, as long as you give those elements the appropriate class name or identifier.

CSS specifications and validation services are maintained by W3C.

 CSS stands for Cascading Style Sheets


 Styles define how to display HTML elements
 Styles were added to HTML 4.0 to solve a problem
 External Style Sheets can save a lot of work
 External Style Sheets are stored in CSS files

CSS Syntax :
A CSS rule has two main parts: a selector, and one or more declarations:

The id Selector is used to specify a style for a single, unique element. It uses the id attribute of the HTML
element, and is defined with a "#".

The class Selector is used to specify a style for a group of elements. This allows you to set a particular style
for any HTML elements with the same class. It uses the HTML class attribute, and is defined with a "."

3 Ways to Style HTML Tags Using CSS


Before we get too far into learning CSS we should know that there are three ways you can apply CSS styling
to your HTML elements and tags.

1. Inline styling using the "style" property of the tag to apply CSS.
2. Place CSS in the <head> tag of the document you want it to affect.
3. Using a separate style sheet

External Style Sheet

An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can
change the look of an entire Web site by changing one file. Each page must link to the style sheet using the
<link> tag. The <link> tag goes inside the head section:

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
5
Internal Style Sheet

An internal style sheet should be used when a single document has a unique style. You define internal styles

<head>
<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
</style>
</head>
in the head section of an HTML page, by using the <style> tag, like this:

Inline Styles

An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this
method sparingly!

To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS
property. The example shows how to change the color and the left margin of a paragraph:

<p style="color:sienna;margin-left:20px">This is a paragraph.</p>

Cascading order

What style will be used when there is more than one style specified for an HTML element?Generally speaking
we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where
number four has the highest priority:

1. Browser default
2. External style sheet
3. Internal style sheet (in the head section)
4. Inline style (inside an HTML element)

Create and Link to CSS Style Sheet

A CSS style sheet is used to add styling to your page elements (tags) in a more organized fashion to help with
code clutter. It is the smarter way to design.

1. Create a new folder inside of your main project folder (where your index.html file lives). Name this
new folder "style".
2. Fire up your HTML editor and create a new blank file named "main.css"
3. Save main.css into the new folder you just created named style
4. Open index.html and add the following line of code inside of your head tag, directly under your title
tag is a good spot.

6
JAVASCRIPT:
Javascript(not to be confused with Java) is a scripting language that is widely used by many developers that
focus on website and web applications creation.

What is JavaScript?

 JavaScript was designed to add interactivity to HTML pages


 JavaScript is a scripting language
 A scripting language is a lightweight programming language
 JavaScript is usually embedded directly into HTML pages
 JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
 Everyone can use JavaScript without purchasing a license

JavaScript was originally developed by a guy named Brendan Eich while working with Netscape. It began
with the name Mocha, then its name was changed to Live Script, and finally this scripting language became
labelled JavaScript which is now set into stone. JavaScript's official name is ECMAScript. ECMAScript is
developed and maintained by the ECMA organization. ECMA-262 is the official JavaScript standard.The
development of ECMA-262 started in 1996, and the first edition of was adopted by the ECMA General
Assembly in June 1997.The standard was approved as an international ISO (ISO/IEC 16262) standard in
1998.The development of the standard is still in progress.

There is a JavaScript library called jQuery which many people have moved to using for making complex
scripting tasks simple.

Implementation

JavaScript is used inside of a web document in three ways. Placing the JavaScript directly in the Head tag of
your document, or by including an external JavaScript file named something like myJavascript.js, and it can
be placed directly into the body section of your document.

<head>
<script language="JavaScript" type="text/javascript">
<!--
var person = "Xyz";
var numOfYears = 493;
var mySentence = person + " has been using Javascript for " + numOfYea
rs + " years.";
//-->
</script>

<script src="myJavascript.js" type="text/javascript"></script>


</head>
<body>
<script language="JavaScript" type="text/javascript">
document.write(mySentence);
</script>
</body>
</html>

7
APACHE HTTP SERVER

The Apache HTTP Server, commonly referred to as Apache is web server software notable for playing a
key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to
surpass the 100 million web site milestone. Apache was the first viable alternative to the Netscape
Communications Corporation web server (currently known as Oracle iPlanet Web Server), and has since
evolved to rival other Unix-based web servers in terms of functionality and performance. The majority of web
servers using Apache run a Unix-like operating system. Apache is a modular server. This implies that only the
most basic functionality is included in the core server. Extended features are available through modules which
can be loaded into Apache. By default, a base set of modules is included in the server at compile-time. If the
server is compiled to use dynamically loaded modules, then modules can be compiled separately and added at
any time using the Load Module directive. Otherwise, Apache must be recompiled to add or remove modules.
Configuration directives may be included conditional on a presence of a particular module by enclosing them
in an <IfModule> block.

Apache is developed and maintained by an open community of developers under the auspices of the Apache
Software Foundation. The application is available for a wide variety of operating systems, including
UNIX, Linux, Solaris, Mac OS X, Microsoft Windows, OS/2, TPF etc. Released under the Apache License,
Apache is characterized as open-source software. Since April 1996 Apache has been the most popular HTTP
server software in use. As of February 2010 Apache served over 54.46% of all websites and over 66% of the
million busiest.
USE
Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web.
Many web applications are designed expecting the environment and features that Apache provides.

Apache is redistributed as part of various proprietary software packages including the Oracle Database and
the IBM Web Sphere application server. It is also supported in some way by Borland in
the Kylix and Delphi development tools. Apache is included with Novell NetWare 6.5, where it is the default
web server. Apache is included with many Linux distributions.Apache is used for many other tasks where
content needs to be made available in a secure and reliable way. Programmers developing web applications
often use a locally installed version of Apache in order to preview and test code as it is being developed.
Performance
Although the main design goal of Apache is not to be the "fastest" web server, Apache does have performance
comparable to other "high-performance" web servers. Instead of implementing a single architecture, Apache
provides a variety of MultiProcessing Modules (MPMs) which allow Apache to run in a process-based, hybrid
(process and thread) or event-hybrid mode, to better match the demands of each particular infrastructure. This
implies that the choice of correct MPM and the correct configuration is important. Where compromises in
performance need to be made, the design of Apache is to reduce latency and increase throughput, relative to

8
simply handling more requests, thus ensuring consistent and reliable processing of requests within reasonable
time-frames
WAMPSERVER
WampServer is a Windows web development environment. It allows you to create web applications with
Apache, PHP and the MySQL database. It also comes with PHPMyAdmin to easily manage your databases.
WampServer installs automatically (installer), and its usage is very intuitive. You will be able to tune your
server without even touching the setting files. WampServer is the only packaged solution that will allow you
to reproduce your production server.

Installing

Double click on the downloaded file and just follow the


instructions. Everything is automatic. The WampServer
package is delivered whith the latest releases of Apache,
MySQL and PHP.

Once WampServer is installed, you can add other releases


by downloading them on this website. They will then
appear in the WampServer menu and you will be able to
switch releases with a simple click.

Functionalities

WampServer functionalities are very complete and easy to use so we won't explain here how to use them.

With a left click on WampServer icon, you will be able to: With a right click:
- manage your Apache and MySQL services - change WampServer menu language
- switch online/offline (give access to everyone or only local - access this page
host)
- install and switch Apache, MySQL and PHP releases
- manage your servers settings
- access your logs
- access your settings files
- create alias

How to start
When you install WampServer, a "www" directory is created (generally c:\wamp\www). Create a directory
inside for your project and put your PHP files in it.
Click on the link "Localhost" in the WampServer menu or open your browser and open the http://localhost
address.

9
INTRODUCTION TO PHP
PHP is an acronym for Hypertext Preprocessor. It is a dynamic server side scripting language that allows an
application developer to create very simple to very complex mechanisms for the web. Think of PHP as the
brain and central nervous system behind your applications. PHP code can be directly mingled in with your
HTML page content as long as the page has a .php extension ( myPage.php ). Or it can be scripts and class
files placed on server and connected to your front-end files. Any HTML file you have can be turned into a
PHP file and PHP script will run inside it.

HISTORY
PHP originally stood for personal home page.[3] Its development began in 1994 when programmer Rasmus
Lerdorf initially created a set of Perl scripts he called 'Personal Home Page Tools' to maintain hispersonal
homepage, including tasks such as displaying his résumé and recording how much traffic his page was
receiving. He rewrote these scripts as C programming language Common Gateway Interface (CGI) binaries,
extending them to add the ability to work with web forms and to communicate with databases and called this
implementation 'Personal Home Page/Forms Interpreter' or PHP/FI. PHP/FI could be used to build simple,
dynamic web applications. Lerdorf released PHP/FI as 'Personal Home Page Tools (PHP Tools) version 1.0'
publicly on June 8, 1995, to accelerate bug location and improve the code. This release already had the basic
functionality that PHP has today. This included Perl-like variables, form handling, and the ability to embed
HTML. The syntax was similar to Perl but was more limited and simpler, although less consistent. A
development team began to form and, after months of work and beta testing, officially released PHP/FI 2 in
November 1997.
Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion IIT, rewrote the parser in 1997 and
formed the base of PHP 3, changing the language's name to the recursive initialise PHP: Hypertext Pre-
processor.[3] Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski
and Gutmans then started a new rewrite of PHP's core, producing the Zend Engine in 1999. They also
founded Zend Technologies in Ramat Gan, Israel. On May 22, 2000, PHP 4, powered by the Zend Engine 1.0,
was released. As of August 2008 this branch is up to version 4.4.9. PHP 4 is no longer under development nor
will any security updates be released.
On July 13, 2004, PHP 5 was released, powered by the new Zend Engine II. PHP 5 included new features
such as improved support for object-oriented programming, the PHP Data Objects (PDO) extension (which
defines a lightweight and consistent interface for accessing databases), and numerous performance
enhancements. In 2008 PHP 5 became the only stable version under development. Late static binding had
been missing from PHP and was added in version 5.3.
PHP File

 PHP files can contain text, HTML tags and scripts


 PHP files are returned to the browser as plain HTML
 PHP files have a file extension of ".php", ".php3", or ".phtml"

Name it: my_webpage.php

PHP blends well into other useful programming languages

PHP's syntax is very similar to ActionScript(used in Flash and Flex) and JavaScript. So when someone learns
any one of these three languages they have a good head start when it comes time to learn the other two. The
logic behind PHP is very easy to understand and master once you create a few applications. PHP can also

10
work in tandem with these other languages. You can send information back and forth when needed, to process
information in any way you want.

Why PHP?

 PHP runs on different platforms (Windows, Linux, Unix, etc.)


 PHP is compatible with almost all servers used today (Apache, IIS, etc.)
 PHP is FREE to download from the official PHP resource: www.php.net
 PHP is easy to learn and runs efficiently on the server side

To get access to a web server with PHP support, you can:

 Install Apache (or IIS) on your own server, install PHP, and MyMYSQL
 Or find a web hosting plan with PHP and MyMYSQL support

Basic PHP Syntax

<html> A PHP scripting block always starts with <?php and ends with ?>. A PHP
<body> scripting block can be placed anywhere in the document. PHP file
normally contains HTML tags, just like an HTML file Each code line in
<?php PHP must end with a semicolon. The semicolon is a separator and is used
echo"HelloWorld"; to distinguish one set of instructions from another.
?>
There are two basic statements to output text with PHP: echo and print. In
</body> the example above we have used the echo statement to output the text
</html> "Hello World".

PHP OPERATIONAL TRAILS:

SERVER

APACHE

FIND PAGES HELLO.PHP

R RETURN PROCESS
HTML

D/B

11
Print Vs. echo

print and echo are both used to output data to browser software or other technologies that intake external
data.

echo() is a language construct, so you are not required to use parentheses with it. If you ever need to pass
more than one parameter to echo(), the parameters must not be enclosed within parentheses.

print() behaves as a Function, but is not actually a function. print is sometimes mistaken as a function by
many programmers since it sets a return value, but it is also a language construct like echo. It simply outputs a
string of data. And you are not required to use parentheses with it.

If you are going to be picky about milliseconds... echo is faster due to the fact that it does not set a return
value like print and most functions do. So there is a difference... but not a noticeable one. Both of these
methods for producing output are widely used, a matter of personal preference, and will perform virtually
the same.

Where to Place PHP Code Blocks?

PHP blocks(tags) can go anywhere you like in a .php web page document. Anywhere. Many PHP developers
choose to make one large PHP block above their <!DOCTYPE> and <html> tags. In this block they would
handle all of the information gathering, parsing, or whatever needs to be scripted. They then make variables
out of information to echo or print the values out to the browser.

Alternately you can choose to have many PHP blocks exactly located in the HTML <head> or <body> section
of the document where that certain data would display.

Variables in PHP

“a symbolic name associated with a value and whose associated value may be changed".

All variables in PHP start with a $ sign symbol.The correct way of declaring a variable in PHP:

$var_name = value;

Global Variables

<?php Global variables are set by a PHP script author to assure that a
// Define your variable and its
value variable and its value will be available inside of a function, or
$data1 = "xyz"; when another PHP file is called to manipulate that variable. When
// Now set it as global you create custom variables in the normal fashion those variables
global $flavor1;
//or can be set as and their values will not be available to you inside of a function or
Predefined Variables
global $flavor1, (aka:
$flavor2, $fla an externally called file. To make sure they are available you
vor3;
create the variable in the normal way and then apply the following
?>
code to make global and available to cover more scope only when
needed
12
Predefined superglobal
There are a set of predefined variables in PHP that are always available for use in any script or scope in your
applications. When data is created, sent, or stored using mechanisms that create superglobal variables, we can
then access those variables sitewide or all throughout our scripts and scope. Predefined superglobals are
available to all of your scripts that are part of a website or application you are creating.

The superglobal variables are:


$_GET Stores any variables created using the GET method
$_POST Stores any variables created using the POST method
$_REQUEST Stores any variables created through a user input script (it can access both POST or GET)
$_FILES Stores any file upload variables created through user input scripts
$_SESSION Stores any variables created through registering session variables
$_COOKIE Stores any variables created through setcookie
$GLOBALS Stores any variables that have been globally defined
$_SERVER Stores server information such as headers, file names, reference paths, and current page.
$_ENV Stores any variables associated with the server environment.

Superglobal variables are created and defined in different ways. We will demonstrate these methods
throughout our lessons, we felt that while we are discussing variables we should tell you about all of the
different types available to you and your scripts.

PHP is a Loosely Typed Language

In PHP, a variable does not need to be declared before adding a value to it.PHP automatically converts the
variable to the correct data type, depending on its value.

Magic Constants (predefined)


PHP also has predefined magic constants available for you to use. Here we demonstrate a few:

<?php
// __LINE__ Returns the current line number of the file.
echo __LINE__;

// __FILE__ Returns the full path and filename of the file.

echo __FILE__;

// __FUNCTION__ Returns the function name the code is currently executing inside of
echo __FUNCTION__;

// __CLASS__ The class name.

echo __CLASS__;
echo "<br />"; 13
?>
PHP Session

A PHP session variable is used to store information about, or change settings for a user session. Session
variables hold information about one single user, and are available to all pages in one application.

When you are working with an application, you open it, do some changes and then you close it. This is much
like a Session. The computer knows who you are. But on the internet there is one problem: the web server
does not know who you are and what you do because the HTTP address doesn't maintain state.

A PHP session solves this problem by allowing you to store user information on the server for later use (i.e.
username, shopping items, etc). However, session information is temporary and will be deleted after the user
has left the website. If you need a permanent storage you may want to store the data in a database.

Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID
is either stored in a cookie or is propagated in the URL.

Before you can store user information in your PHP session, you must first start up the session.
<?php session_start(); ?>

<html>
<body>………</body>
</html>

The code above will register the user's session with the server, allow you to start saving user information, and
assign a UID for that user's session.

If you wish to delete some session data, you can use the unset() or the session_destroy() function.

<?php
unset($_SESSION['views']); The unset() function is used to free the specified session variable:
?>

You can also completely destroy the session by calling the session_destroy() <?php
function: session_destroy();
?>

PHP Looping - For Loops

FOR LOOP: used when you know in advance how many times the script should run.

for (init; condition; increment) Parameters:


{
code to be executed;  init: Mostly used to set a counter (but can be any
} code to be executed once at the beginning of the
loop)
 condition:
14 Evaluated for each loop iteration. If it
evaluates to TRUE, the loop continues. If FALSE,
the loop ends.
 increment: Mostly used to increment a counter (but
can be any code to be executed at the end of the
loop)
foreach ($array as $value)
FOREACH LOOP: used to loop through arrays. {
code to be executed;
}

PHP Function
A function will be executed by a call to the function.

PHP function guidelines:


function functionName()
{  Give the function a name that reflects what the function
code to be executed;
}
does
 The function name can start with a letter or underscore
(not a number)

Function Arguments:
We pass arguments to our functions in order to process variable data and display, store, or return results.

Some functions can be sent an argument(value) or set of arguments for the function to perform operations on.
The function argument variables get placed inside the function's parentheses when you create it. The value for
the arguments are sent to the function from inside of the parentheses of the function calling code
<?php
// custom function will not fire off until we call it
function my_function ($var1) {

echo "Hello World!" . $var1;

}
// Make the function run here by calling it now and adding an arguement value
my_function (" This is a user defined function being fed one arguement.");
?>

Output:

Hello World! This is a user defined function being fed one argument.

String
A string is any one or set of alphanumeric characters and spaces. A string may include letters, numbers,
spaces, or symbols. When we create an HTML contact form for a website we might have name, email, phone
number, and message fields. When the user types their information in and press submit, all of that information
in all of those fields are interpreted as strings The name is a string, the email, the phone number, and finally
the message, all are strings and all will be interpreted as string data when it comes time to parse it.

A string is simply one or any set of alphanumeric characters, spaces, and symbols.

15
ARRAYS:
An array stores multiple values in one single variable.Each element in the array has its own index so that it
can be easily accessed. In PHP, there are three kinds of arrays:

 Numeric array - An array with a numeric index


 Associative array - An array where each ID key is associated with a value
 Multidimensional array - An array containing one or more arrays

Including and Requiring Files


When you use the include(), include_once(), require(), or require_once() statements in PHP you are
instructing a certain file and all of its contents to be "included" into your script that is calling it. This is very
handy for making modular reusable code structures, even in simple applications.

The include() statement will include the desired file if the file can be found through the path specified in the
statement. If the desired file cannot be found, no errors will occur, but the file and its contents will not be
included. The same file can be included multiple times into the calling script. Using include_once() you can
command the calling script to only include a certain file one time and no more.

The require() statement works a lot like the include() statement in the respect that will bring another file and
its contents into the calling script. The big difference is that using require() will "require" the file to be at the
specified location on server. If the desired file to require cannot be found, an error will occur in your script,
and the script will terminate. Using require_once() you can command the calling script to only require a
certain file one time and no more.

For the following code examples we first need a file to include, let's create that now:
//my_file.php //Include file my_file.php

<?php <?php
$var1 = "Hello World!"; include ("my_file.php");
?> echo $var1;
?>

Output:

Hello World!

Using the include or require statements we can also perform cross domain scripting from one server, to a
completely different server. It remains on your server but you can allow other sites to connect to it.

Usage
PHP primarily acts as a filter, taking input from a file or stream containing text and/or PHP instructions and
outputs another stream of data; most commonly the output will be HTML. PHP has also attracted the
development of many frameworks that provide building blocks and a design structure to promote rapid
application development (RAD). AS of April 2007, over 20 million Internet domains had web services hosted
on servers with PHP installed and mod_php was recorded as the most popular Apache HTTP
Server module. Significant websites are written in PHP including the user-facing portion
of Facebook, Wikipedia (MediaWiki), and Digg Joomla, eZ Publish, WordPress, Drupal and Moodle.

16
PHP DATABASE :MYSQL
MySQL is the most popular open-source database system.
MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user
access to number of databases.
MySQL is currently the world’s most popular and widely used open source database technology and data
storage system. MySQL offers great reliability and ease of use. It is free, and comes with free documentation
as well as thousands of programmers that share their code that relates to communicating with a MySQL
database. The MySQL development project has made its source code available under the terms of the GNU
General Public License, as well as under a variety of proprietary agreements. MySQL was owned and
sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.
You can think of a MySQL database as a container that holds string (text based) data. Images, media files,
audio files, and things of that nature really should not be stored in a database. The trick is to put those files on
the server in folders and just reference their name and path in the database.
MySQL is also used in many high-profile, large-scale World Wide Web products
including Wikipedia, Google and Facebook.
Platform and interfaces:
MySQL is written in C, and C++. Its MYSQL parser is written in yacc, and a home-brewed lexical
analyser named MySQL_lex.cc In addition, an ODBC interface called MyODBC allows additional
programming languages that support the ODBC interface to communicate with a MySQL database, such
as ASP or ColdFusion
Official
The official MySQL Workbench is a free integrated environment developed by MySQL AB that enables users
to graphically administer .Similar to other third-party packages but still considered the authoritative MySQL
frontend; MySQL Workbench lets users manage the following:

 Database design & modeling


 MYSQL development — replacing MySQL Query Browser
 Database administration — replacing MySQL Administrator
MySQL Workbench is available in two editions, the regular free and open source Community Edition which
may be downloaded from the MySQL website, and the proprietary Standard Edition which extends and
improves the feature set of the Community Edition.
MySQL is one of those languages that PHP seems to mesh with very well, and the open source community is
constantly adding a more expansive and useful structure to the language. We used PHP to open connections,
close connections, select data from the database, parse it, and much more.
Here are the main parts of a MySQL database and a quick description of what purpose they serve.
Database - Database is the main text based container that holds everything for your application, think
of it as the big box that holds a lot of text strings and text blocks. Most hosting companies
allow you to create many, and it is as easy as a few clicks to create them. Images and web
pages get stored on your server, not in a database. Databases are used for text strings
traditionally. And it can hold lots of text strings.

Table - Tables get created inside of your Database. Your database can hold multiple tables.
www.developphp.com's database has multiple tables. One table holds all of the data that
you put into the join form here(name, email, location, password, etc...). Another table
17
holds and updates information about how many times tutorials here have been viewed, by
whom, and from where. And another table in the database holds the forum posts, and so on
and so forth with everything this site does.

Field - Fields are the slots where information is delivered. The field labelled "first_name" in a
table would no doubt receive the user's first name when you write your script. So you
create your table and fields, then write forms and scripts to have people place their data
into the database. Or write scripts that update your database automatically on certain
events.

Row - A Row is each information set sent to the database. For instance, when you joined this site
you became a new row in our database table. That row consists of the fields: name, email,
location, password, zodiac, sign up date, ip address, and a few other things. If a girl named
Jane joins this site tomorrow, her info will become a new row in our member table in our
database. If our site has 250 members, there will be 250 rows in the database.

What Can MySQL do?

 Execute queries against a database


 Retrieve data from a database
 Insert records in a database
 Can update records in a database
 Delete records from a database
 Create new databases
 Create new tables in a database
 Create stored procedures in a database
 Create views in a database
 Set permissions on tables, procedures, and views

Using MySQL in Your Web Site

To build a web site that shows some data from a database, you will need the following:

 An RDBMS database program (i.e. MS Access, SQL Server, MySQL)


 A server-side scripting language, like PHP or ASP.
 SQL
 HTML / CSS

RDBMS

RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL, and for all
modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access. The data
in RDBMS is stored in database objects called tables.

PHPMyAdmin: MySQL Database Management Software


PHPMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL over
the World Wide Web. PHPMyAdmin supports a wide range of operations with MySQL. The most frequently
used operations are supported by the user interface (managing databases, tables, fields, relations, indexes,
users, permissions, etc.), while you still have the ability to directly execute any MYSQL statement.
PHPMyAdmin has a great intuitive user interface made for the specific task of database management. Best of
all the software is free. PHPMyAdmin will teach a beginner the code to structure a database if the user clicks
18
to see the PHP and query that made the action take place. So in other words, anytime you do anything to your
database, you can click "show PHP code" to see the scripting used to make that action occur. PHPMyAdmin
is much more than just a database management tool.
Connecting to Your Database

In PHP, this is done with the MySQL_connect() function.

mysql_connect(servername,username,password);

Parameter Description
servername Optional. Specifies the server to connect to. Default value is "localhost:3306"
username Optional. Specifies the username to log in with. Default value is the name of the user that
owns the server process
Password Optional. Specifies the password to log in with. Default is ""

<?php
$con = mysql_connect("localhost","XYZ","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// some code
?>

19
CONCLUSION
We have studied PHP and its features. The key considerations were summed up by the PHP team in the
following list of buzzwords:

 Simple

 Secure

 Portable

 Robust

 Open source

PHP is a dynamic server side scripting language that allows an application developer to create very simple
to very complex mechanisms for the web. PHP primarily acts as a filter, taking input from a file or stream
containing text and/or PHP instructions and outputs another stream of data; most commonly the output will be
HTML. PHP has also attracted the development of many frameworks that provide building blocks and a
design structure to promote rapid application development (RAD). AS of April 2007, over 20 million
Internet domains had web services hosted on servers with PHP installed and mod_php was recorded as the
most popular Apache HTTP Server module. Significant websites are written in PHP including the user-facing
portion of Facebook, Wikipedia (MediaWiki), and Digg Joomla, WordPress, Drupal and Moodle.
Also, we have studied PHPMyAdmin which is a free software tool written in PHP intended to handle the
administration of MySQL over the World Wide Web. PHPMyAdmin supports a wide range of operations with
MySQL. The most frequently used operations are supported by the user interface (managing databases, tables,
fields, relations, indexes, users, permissions, etc.), while you still have the ability to directly execute any
MYSQL statement.
PHPMyAdmin has a great intuitive user interface made for the specific task of database management. Best of
all the software is free. PHPMyAdmin will teach a beginner the code to structure a database if the user clicks
to see the PHP and query that made the action take place. So in other words, anytime you do anything to your
database, you can click "show PHP code" to see the scripting used to make that action occur. PHPMyAdmin
is much more than just a database management tool.

20
REFRENCES
1. PHP Cookbook: 2nd edition by O’REILLY MEDIA
2. Core PHP Programming: 3rd edition by LEON ATKINSON
3. Webdatabase applications Cookbook: 2nd edition by O’REILLY MEDIA
4. http://www.developphp.com/list_php.php
5. http://www.w3schools.com/PHP/php_intro.asp
6. http://www.php.net
7. http://www.mysql.com/training/

21

You might also like