In this presentation, I covered following topics:
1. Introduction
2. Characteristics of PHP
3. PHP Tag
4. Variables and type of variables
5. Datatypes
6. Operators
7. Decision-making Statements
8. Looping Statements
9. Arrays
10. Functions
11. Cookies
12. PHP and MySQL
2. PHP stands for Hypertext PreProcessor.
PHP is a server side scripting language that is
embedded in HTML.
PHP allows web developers to create dynamic
web pages.
It is integrated with a number of popular
databases, including MySQL, PostgreSQL,
Oracle, Sybase, Informix and SQL Server.
3. PHP was written in the C programming language
by Rasmus Lerdorf in 1994.
PHP originally stood for “Personal Home Page”.
5. PHP code must be included inside one of the 3
special markup tags:
<?php PHP CODE HERE ?>
<? PHP CODE HERE ?>
<script language=“php”>
PHP CODE HERE
</script>
7. Variables are used to store the data.
Here are the most important things about
variables in PHP:
i. All variables are denoted with a leading dollar
sign($).
ii. Variables do not have intrinsic types.
iii. PHP does a good job of automatically converting
types from one to another when necessary.
8. PHP variables can be one of four scope types:
i. Local variables
ii. Function parameters
iii. Global variables
iv. Static variables
9. A constant is a name or an identifier for a simple
value.
A constant value cannot change during the execution
of the script.
To define a constant you have to use define()
function and to retrieve the value of a constant.
You can also use the function constant() to read a
constant’s value.
10. PHP has 8 datatypes:
i. Integers
ii. Doubles
iii. Booleans
iv. NULL
v. Strings
vi. Arrays
vii. Objects
viii. Resources
11. n is replaced by the newline character
r is replaced by the carriage-return character
t is replaced by the tab character
$ is replaced by the dollar sign itself ($)
" is replaced by a single double-quote (")
is replaced by a single backslash ()
15. if-else Statement
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
16. elseif Statement
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;
17. Switch Statement
switch (expression)
{
case label1:
code to be executed if expression = label1;
break;
case label2:
code to be executed if expression = label2;
break;
default:
code to be executed if expression is different from
above labels;
}
18. for Statement
for (initialization; condition; updation)
{
code to be executed;
}
22. An array is a data structure that stores one or
more type of values in a single variable.
Types of Arrays:
i. Numeric Array
ii. Associative Array
iii. Multidimensional Array
23. These arrays can store numbers, strings and any
object.
Here we have used array() function to create
array.
24. Associative array will have their index as string
so that you can establish a strong association
between key and values.
Creating Array:
$array_name=array(“str1”=>value1,
“str2”=>value2, ……
“strn”=>valuen);
Accessing Array Elements:
$array_name[‘str1’];
25. A multi-dimensional array each element in the
main array can also be an array and each element
in the sub-array can be an array and so on.
26. A function is a piece of code which takes one or
more input in the form of parameter and does
some processing and returns a value.
Creating Function
function function_name(parameters list)
{
/* Code Here */
}
Calling Function
function_name(parameters list);
27. Cookies are text files stored on the client computer
and they are kept of use tracking purpose.
There are 3 steps involved in identifying returning
users:
i. Server script sends a set of cookies to the browser.
ii. Browser stores this information on local machine for
future use.
iii. Next time, when the browser sends any request to the
web server, it sends those cookies information to the
server and server uses that information to identify the
user.
28. PHP provided setcookie() function to set a cookie.
setcookie(name,value,expire,path,domain,security);
To access cookies, use either $_COOKIE[name] or
$HTTP_COOKIE_VARS[name] variables.
You can use isset() function to check if a cookie is set or
not.
29. CONNECTING TO MYSQL DATABASE
Opening a Database Connection
connection mysql_connect(dbserver, user, password,
new_link, client_flag);
Closing Database Connection
bool mysql_close(resource $link_identifier);
30. Selecting a Database
$retval=bool mysql_select_db(dn_name,connection);
Creating a Database/Executing Query
bool mysql_query(sql,connection);
Retrieving Data from Database
mysql_fetch_array($retval, type_array);
mysql_fetch_assoc($retval);