Download php

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft SQL Server wikipedia , lookup

Database model wikipedia , lookup

Clusterpoint wikipedia , lookup

Navitaire Inc v Easyjet Airline Co. and BulletProof Technologies, Inc. wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Transcript
8th Semester, Batch 2009
Department Of Computer Science
SSUET
Web Server Software &
Programming/Scripting Language:
When setting out to build a site, products you need
are as follows.
 Web server software
 Database management system
 Programming/scripting language
 Hardware for the web server
 An Operating system
Web Server Software &
Programming/Scripting Language:
 Some of these are dependent on others for example
not all operating run on all hardware and not all
scripting can connect to any other database. From the
above products for developing any website the three
main ingredients that plays major role for developing
websites, and to work the websites professionally, for
retrieving web pages, ensuring secure data storage are
Web server soft wares , database management system,
scripting language.
Web Server Software:
 A computer program that is responsible for accepting
HTTP requests from web clients, which are known as
web browsers and serving them HTTP responses along
with optional data contents, which usually are web
pages such as HTML documents and linked objects
(images, etc.).
 Internet Information server IIS
 Apache
Database management system:
 A database management system should be there at
server side, which enables you to store, retrieve, search
and sort the data. The database should provide access
to the data; it must allow multiple user access
concurrently and only authorized person access.
 Sql Server
 My Sql
 Oracle
Programming/Scripting Language:
 Programming languages are used to design your web
pages. The choice of programming depend on that it
should have easy connectivity with the database, it
should be platform independent
 ASP.Net
 PHP
 Java server pages
 Perl
What is PHP?
 PHP is a server side scripting language designed for
developing websites. Within an HTML page you can
embed PHP code which is executed each time the page
is visited. Your page is interpreted at web server and
generates HTML code, which your browser can
understand.
What is MySQL?
 MySql is a fast, robust database management system,
which enables you for the data accessing according to
request. Mysql control accessing of the data to ensure
that multiple user can work with it concurrently, so
that the accessing to the data can be possible through
world wide.
Some of PHP’s Strength:
 PHP also offers features like other programming
language like high performance, integration to many
different databases, built in libraries, strong object
oriented support, but the main features which can
meet the requirement that make the PHP best choice
are:
 Cost
 Portability
 Open source
Some of PHP’s Strength:
 Cost:
 PHP is free. You can download the latest version at any time for no cost.
 Portability:
 PHP can work on Cross platform. You can write your PHP code on
multiple platforms. It will work on UNIX, Linux, Solaris or any other
version of Microsoft Windows, due to this nature it offers;
 LAMPP(Linux Apache MySQL PHP)
 WAMPP(Windows Apache MySQL PHP)
 Open Source:
 You have access to PHP source code it does not demand for any license.
Unlike closed source product you are free to make any change to the
code
Basic PHP Syntax:
 A PHP scripting block always starts with <?php and
ends with ?>. A PHP file normally contains HTML
tags, just like an HTML file, and some PHP scripting
code. Below, we have an example of a simple PHP
script which sends the text "Hello World" to the
browser.
Basic PHP Syntax:








Example:
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
 Each code line in PHP must end with a semicolon. The
semicolon is a separator and is used to distinguish one set
of instructions from another
Comments in PHP:
 In PHP, we use // to make a single-line comment or /* and









*/ to make a large comment block.
Example:
<html>
<body>
<?php
// This is a comment
/* This is a comment block */
?>
</body>
</html>
Variables in PHP:
 The correct way of setting a variable in PHP:
 Example1:
 $var_name = value; Example2:
 <?php
 $txt = "Hello World!";
 $number = 16;
 ?>
PHP is a Loosely Typed Language:
 In PHP a variable does not need to be declared before
being set. In the example above, you see that you do
not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct
data type, depending on how they are set. In a strongly
typed programming language, you have to declare
(define) the type and name of the variable before
using it. In PHP the variable is declared automatically
when you use it.
Strings in PHP
 Example
 <?php
 $txt="Hello World";
 echo $txt;
 ?>
The Concatenation Operator:
 There is only one string operator in PHP. The
concatenation operator (.) is used to put two string
values together. To concatenate two variables together,
use the dot (.) operator.
Example:
 <?php
 $txt1="Hello World";
 $txt2="1234";
 echo $txt1 . " " . $txt2;
 ?>
The Concatenation Operator:
 Output of the code above is:
 Hello World 1234
Using the strlen() function:
 The strlen () function is used to find the length of a
string.
 Example:
 <?php
 echo strlen("Hello world!");
 ?>
 The output of the code above will be:
 12
Using the strpos() function
 The strpos() function is used to search for a string or
character within a string. If a match is found in the
string, this function will return the position of the first
match. If no match is found, it will return FALSE.
 Example:
 <?php
 echo strpos("Hello world!","world");
 ?>
Using the strpos() function
 The Output of the above code is. 6
 As you see the position of the string "world" in our
string is position 6. The reason that it is 6, and not 7, is
that the first position in the string is 0, and not 1.
Conditional Statements
 if...else statement - use this statement if you want to
execute a set of code when a condition is true and
another if the condition is not true
 elseif statement - is used with the if...else statement
to execute a set of code if one of several condition are
true
The If...Else Statement
 If you want to execute some code if a condition is true
and another code if a condition is false, use the if....
else statement.
 Syntax:
 if (condition) code to be executed if condition is
true;else code to be executed if condition is false;
The If...Else Statement











Example:
<html>
<body>
<? php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
</body>
</html>
?>
The ElseIf Statement
 If you want to execute some code if one of several
conditions are true use the elseif statement Syntax:
 if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
The ElseIf Statement
 Example:
 The following example will output "Have a nice weekend!" if the current day is Friday,
and "Have a nice Sunday!" if the current day is Sunday. Otherwise it will output "Have a
nice day!".













<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
</html>
The PHP Switch Statement
 Use the switch statement to select one of many blocks of code to
be executed.
 Syntax
 switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
default:
code to be executed if n is different from both label1 and label2;
}
The PHP Switch Statement


Example
<html>
<body>
<?php
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>
</body>
</html>