Chapter 1 Introduction To PHP

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 31

PHP/MySQL

Part I
Introduction to PHP
CHAPTER ONE

Why PHP and MySQL?


In this chapter you will learn

 Understanding PHP and MySQL

 The benefits of using PHP and MySQL


What is PHP?
 PHP is the web development language written by and for
web developers.
 PHP stands for PHP: Hypertext Preprocessor. The
product was originally named Personal Home Page Tools,
and many people still think that’s what the acronym stands
for, but as it expanded in scope, a new and more
appropriate name was selected by community vote.
What is PHP (cont’d)
 PHP is a server - side scripting language that allows
your web site to be truly dynamic.
 Its flexibility and relatively small learning curve
(especially for programmers who have a background
in other programming languages like C, Java and
Perl) make it one of the most popular scripting
languages used today.
What is PHP (cont’d)
 PHP is currently in its sixth major rewrite, called PHP6 or
just plain PHP.

 PHP is a server-side scripting language, usually used to


create web applications in combination with a web
server, such as Apache.

 PHP can also be used to create command-line scripts


akin to Perl or shell scripts, but such use is much less
common than PHP’s use as a web language.
What is PHP (cont’d)

 In fact, most of what PHP does is invisible to


the end user. Someone looking at a PHP
page will not necessarily be able to tell that it
was not written purely in Hypertext Markup
Language (HTML), because the result of
PHP is usually HTML.
What is PHP?
 PHP == ‘Hypertext Preprocessor’
 Open-source, server-side scripting language
 Used to generate dynamic web-pages
 PHP scripts reside between reserved PHP tags
 This allows the programmer to embed PHP

scripts within HTML pages


What Is MySQL?
 MySQL (pronounced My Ess Q El) is an open source,
SQL relational database management system
(RDBMS) that is free for many uses.
 MySQL, is the database construct that enables PHP
and Apache to work together to access and display
data in a readable format to a browser. It is a
Structured Query Language (SQL) server designed
for heavy loads and processing of complex queries.
What Is MySQL (cont’d)
 As a relational database system, MySQL allows many
different tables to be joined together for maximum
efficiency and speed.
 MySQL is the perfect choice for providing data via the
Internet because of its ability to handle heavy loads,
its advanced security measures and (depending on
who you ask) it ’ s easier to manage than some of the
other open source database servers available.
How to Run PHP Files
 If you double click on a HTML file (files with .html or
.htm extension), it would open on your web browser.
But same won’t happen if you double clicked on a
PHP file (probably it would open in an editor). The
reason is PHP files first need be processed in a web
server before sending their output to the web browser.
How to Run PHP Files (cont’d)
 Therefore before running PHP files, they should be
placed inside the web folder of a web server and then
make a request to desired PHP file by typing its URL in
the web browser. If you installed a web server in your
computer, usually the root of its web folder can be
accessed by typing http://localhost in the web
browser. So, if you placed a file called hello.php inside
its web folder, you can run that file by
calling http://localhost/hello.php.
How to Run PHP Files (cont’d)
 Web folder can be changed based on your web host
(if you hosted your web site online) or the method
you installed the web server in your computer. 
If you used XAMPP to install Apache (web server) in
your computer then the web folder would
be htdocs which is under the root directory of
XAMPP.
Deciding on a Web Application
Platform
 There are many platforms upon which web

applications can be built. This section

compares PHP to a few other platforms and

highlights some of PHP’s and MySQL’s

strengths.
Cost
 PHP is one of the “P’s” in the popular LAMP stack.
The LAMP stack refers to the popular combination of
Linux, Apache, MySQL, and PHP/Perl/Python that
runs many web sites and powers many web
applications. Many of the components of the LAMP
stack are free, and PHP is no exception.
 PHP is free, as in there is no cost to develop in and
run programs made with PHP.
Cost (cont’d)
 Both PHP and MySQL run on a variety of
platforms, including many variants of Linux,
Microsoft Windows, and others. Running on
an operating system such as Linux gives the
opportunity for a completely free web
application platform, with no up-front costs.
Cost (cont’d)
 Years of real-world experience with Linux,
Apache, MySQL, and PHP in production
environments has proved that the total cost of
maintaining these platforms is lower, many
times much lower, than maintaining an
infrastructure with proprietary, non-free
software.
Ease of Use
 When compared to many other programming
languages, PHP makes it easy to develop powerful web
applications quickly. Many of the most useful specific
functions (such as those for opening a connection to an
Oracle database or fetching e‑mail from an Internet
Message Access Protocol [IMAP] server) are redefined
for you. A lot of complete scripts are waiting out there
for you to look at as you’re learning PHP.
HTML-embeddedness

 PHP can be embedded within HTML. In other


words, PHP pages are ordinary HTML pages
that escape into PHP mode only when
necessary.
 Here is an example:
<HEAD>
<TITLE>Example.com greeting</TITLE>
</HEAD>
<BODY>
<P>Hello,
<?php
// We have now escaped into PHP mode.
// Instead of static variables, the next three lines
// could easily be database calls or even cookies;
// or they could have been passed from a form.
$firstname = ‘Joyce’;
$lastname = ‘Park’;
$title = ‘Ms.’;
echo “$title $lastname”;
// OK, we are going back to HTML now.
?>
. We know who you are! Your first name is <?php echo
$firstname; ?>.</P>
<P>You are visiting our site at <?php echo date(‘Y-m-d H:i:s’);
?></P>
<P>Here is a link to your account management page: <A
HREF=”http://www.example.com/accounts/<?php echo
“$firstname$lastname”; ?>/“><?php echo $firstname; ?>’s account
management page</A></P>
</BODY>
</HTML>
 When a client requests this page, the web server
preprocesses it. This means it goes through the page
from top to bottom, looking for sections of PHP, which
it will try to resolve. For one thing, the parser will suck
up all assigned variables (marked by dollar signs) and
try to plug them into later PHP commands (in this
case, the echo function). If everything goes smoothly,
the preprocessor will eventually return a normal HTML
page to the client’s browser, as shown in Figure
Cross-platform compatibility

 PHP and MySQL run native on every popular


flavor of Linux/Unix (including Mac OS X) and
Microsoft Windows. A huge percentage of the
world’s Hypertext Transfer Protocol (HTTP)
servers run on one of these two classes of
operating systems.
Cross-platform compatibility (cont’d)

 PHP is compatible with the leading web servers:


Apache HTTP Server for Linux/Unix and
Windows and Microsoft Internet Information
Server. It also works with several lesser-known
servers. Specific web server compatibility with
MySQL is not required, since PHP will handle all
the dirty work for you.
Stability
 The word stable means two different things in this context:
 The server doesn’t need to be rebooted or restarted often.

 The software doesn’t change radically and incompatibly

from release to release.


 To our advantage, both of these connotations apply to

both MySQL and PHP.


 Apache Server is generally considered the most stable of

major web servers, with a reputation for


enviable uptime percentages. Most often, a server reboot
isn’t required for each setting change. PHP
inherits this reliability; plus, its own implementation is solid.
Many extensions

 PHP makes it easy to communicate with other


programs and protocols. The PHP development
team seems committed to providing maximum
flexibility to the largest number of users.
Fast feature development

 Users of proprietary web development


technologies can sometimes be frustrated by the
glacial speed at which new features are added
to the official product standard to support
emerging technologies. With PHP, this is not a
problem.
Not proprietary

 The history of the personal computer industry to


date has largely been a chronicle of proprietary
standards: attempts to establish them, clashes
between them, their benefits and drawbacks for
the consumer, and how they are eventually
replaced with new standards.
Strong user communities
 PHP is developed and supported in a collaborative
fashion by a worldwide community of users.
 The main advantage for most new users is technical
support without charge, without boundaries, and
without the runaround. People on the mailing list are
available 24/7/52 to answer your questions, help
debug your code, and listen to your gripes. The
support is human and real.
Summary

 PHP and MySQL, individually or together, aren’t the


panacea for every web development problem, but
they present a lot of advantages. PHP is built by web
developers for web developers and supported by a
large and enthusiastic community. MySQL is a
powerful standards-compliant RDBMS that comes in
at an extremely competitive price point, even more.
Summary
 By now, you should have an idea of what AMP
is and how it fits into the world of open source
software.
 You know that the abbreviation AMP refers to
pache, MySQL, and PHP, all of which work
together to help you develop dynamic web
sites.

You might also like