PHP Basics
PHP Basics
PHP Basics
1.What is PHP?
2.What is a PHP File?
3.Why PHP?
4.Basic PHP Syntax
5.Variables in PHP
6.Arrays in PHP
7.PHP Functions
8.File Handling
9.Cookies
10.Sessions
11.My SQL Intro
12.Error Handling
13.Conclusion
What is PHP?
• PHP stands for PHP: Hypertext Preprocessor
• PHP is a server-side scripting language, like
ASP
• PHP scripts are executed on the server
• PHP supports many databases (MySQL,
Informix, Oracle, Sybase, Solid,
PostgreSQL, Generic ODBC, etc.)
• PHP is an open source software
• PHP is free to download and use
What is a 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“
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
Basic PHP Syntax
• A PHP scripting block always starts with <?php and ends with
?>
. <?php
?>
• If the file has a .html extension, the PHP code will not be
executed.
Variables in PHP
• $var_name = value;
Example:
<?php
$txt="Hello World!";
$x=16;
?>
• PHP is a Loosely Typed Language
• $cars1="Saab";
• $cars2="Volvo";
• $cars3="BMW";
<html>
<body>
<?php
function writeName()
{
echo “ ragavan;
}
</body>
</html>
Output:
This is ragavan
PHP $_GET Function
When the user clicks the "Submit" button, the URL will look like
this:
• http://www.w3schools.com/welcome.php
The PHP $_REQUEST Function
Example:
Welcome <?php echo $_REQUEST["fname"]; ?>!<br />
You are <?php echo $_REQUEST["age"]; ?> years old
<?php
$file = fopen("test.txt","r");
fclose($file);
?>
Check End-of-file
Syntax
• mysql_connect(servername,username,pass
word);
Continues….
Parameter Description :