SlideShare a Scribd company logo
PHP FUNCTIONS
•Functions in PHP
•PHP Form
•Post And Get Method
•Usage of PHPMYADMIN
•Making Database
•MYSQL
•PHP data base connectivity
Functions are the group of statements that you can execute as a
single unit. Function definations are the lines of code that make up a
function
The syntax for defining a function is:
<?php
function name function(parameters) {
statements;}
?>
There are two types of functions.
1. Built-in functions.
2. User defined functions.
PHP has lots of built-in functions that we use all the time.
Some of the function are given below:
•PHP Array Functions
•PHP Calendar Functions
•PHP File System Functions
•PHP MySQL Functions
•Math functions
These functions allow you to interact with and manipulate arrays in
various ways. Arrays are essential for storing, managing, and operating on
sets of variables. Some Array Functions are:
Array(), Array push(), Array pop() etc.
<html>
<body>
<?php
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
</body>
</html>
<html>
<body>
<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
</body></html>
<html>
<body>
<?php
$a=array("red","green","blue");
array_pop($a);
print_r($a);
?>
</body></html>
The calendar extension presents a series of functions to simplify converting
between different calendar formats. Some PHP Calendar Functions are:
Cal info(), Cal days in month() etc.
<html>
<body>
<?php
print_r(cal_info(0));
?>
</body>
</html>
<html>
<body>
<?php
$d=cal_days_in_month(CAL_GREGORIAN,2,1965);
echo "There was $d days in February 1965.<br>";
$d=cal_days_in_month(CAL_GREGORIAN,2,2004);
echo "There was $d days in February 2004.";
?>
</body>
</html>
The filesystem functions are used to access and manipulate the filesystem
PHP provides you all the posible functions you may need to manipulate a
file.
List:
Copy(), delete(), file(), filetype() etc
These are functions dealing with MySQL handling and logging or to control
the MySQL through PHP functions.
List:
mysql_close(), mysql_connect() etc.
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
The math functions can handle values within the range of integer and
float types.
List:
hexdec(), sqrt(), sin() etc
<?php
echo hexdec("1e") . "<br>";
echo hexdec("a") . "<br>";
echo hexdec("11ff") . "<br>";
echo hexdec("cceeff");
?>
<?php
echo(sqrt(0) . "<br>");
echo(sqrt(1) . "<br>");
echo(sqrt(9) . "<br>");
echo(sqrt(0.64) . "<br>");
echo(sqrt(-9));
?>
<?php
echo(sin(3) . "<br>");
echo(sin(-3) . "<br>");
echo(sin(0) . "<br>");
echo(sin(M_PI) . "<br>");
echo(sin(M_PI_2));
A user defined function is a user-defined set of commands that
are carried out when the function is called.
Function functionName()
{
code to be executed;
}
•A function should start with keyword function and all the function code
should be put inside { and } brace.
•A function name can start with a letter or underscore not a number.
•The function names are case-insensitive.
•Information can be passed to functions through arguments. An argument
is just like a variable.
•Arguments are specified after the function name, inside the parentheses.
•You can add as many arguments as you want, just separate them with a
comma.
<?php
function say_hello() {
echo “<p>Hello everybody!</p>”;
}
say_hello();
Function writeMSg() {
Echo “How are You?”;
}
writeMsg();
?>
<?php
function familyName($fname)
{
echo "$fname Refsnes.<br>";
}
familyName("Jani");
familyName("Hege");
familyName("Kai Jim");
familyName("Borge");
?>
<?php
function familyName($fname,$year)
{
echo “Name of Person is $fname. Born in $year <br>";
}
familyName(“Zeeshan Ahmed","1993");
familyName(“Abdul wahab","1992");
familyName(“Rashid Nawaz","1993");
familyName(“Saad Sattar","1991")
?>
If we call the function setHeight() without arguments it takes
the default value as argument:
<?php
function setHeight($minheight=50)
{
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>
When you create a form you have two choices for the METHOD
attribute. You can use one of the following two methods to pass
information between pages.
• GET method
• POST method
They both pass the data entered into the form along with the
form field name to the web server.
Information sent from a form with the GET method is visible to
everyone (all variable names and values are displayed in the URL). GET also
has limits on the amount of information to send. The limitation is about
2000 characters. However, because the variables are displayed in the URL,
it is possible to bookmark the page. This can be useful in some cases.
GET should NEVER be used for sending passwords or other sensitive
information!
<html>
<body>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
 Information sent from a form with the POST method is invisible to
others (all names/values are embedded within the body of the
HTTP request) and has no limits on the amount of information to
send.
 However, because the variables are not displayed in the URL, it is
not possible to bookmark the page.
 Developers prefer POST for sending form data.
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
 Both GET and POST create an array (e.g. array( key => value, key2 =>
value2, key3 => value3, ...)). This array holds key/value pairs, where keys
are the names of the form controls and values are the input data from
the user.
 Both GET and POST are treated as $_GET and $_POST. These are
superglobals, which means that they are always accessible, regardless of
scope - and you can access them from any function, class or file without
having to do anything special.
 $_GET is an array of variables passed to the current script via the URL
parameters.
 $_POST is an array of variables passed to the current script via the HTTP
POST method.
•PhpMyAdmin is a handy, graphical administration tool written in php for
creating and managing MySQL databases , using a web user interface.
•The interface is straight-forward and easy to learn and it allows users to
execute SQL queries manually.
•It is also open source, so you can download and use it for free.
•Create, drop, browse and modify databases.
•Perform maintenance on databases.
•Run query operations, drop, create, update, check, repair tables and
more.
•Manage MySQL users and privileges.
PHP FUNCTIONS
 You can access phpMyAdmin directly visiting the following URL;
 http://localhost/phpMyAdmin
Or your server ip address
http://127.0.01/phpmyadmin
PHP FUNCTIONS
PHP FUNCTIONS
PHP FUNCTIONS
PHP FUNCTIONS
PHP FUNCTIONS
MySQL also called "My Sequel" is the world's second most widely
used open-source relational database management system (RDBMS).
MySQL is a relational database management system (RDBMS), with
no GUI tools to administer MySQL databases or manage data contained
within the databases.
Users may use the included command line tools, or use MySQL "front-
ends", desktop software and web applications that create and manage
MySQL databases, build database structures, back up data, and work
with data records.
The official set of MySQL front-end tools, MySQL Workbench is actively
developed by Oracle, and is freely available for use.
 The official MySQlworkbench is a free integrated environment
developed by MySQL , that enables users to graphically administer
MySQL databases and visually design database structures. MySQL
Workbench replaces the previous package of software, MYSQL GUI
Table. Similar to other third-party packages, but still considered the
authoritative MySQL front end, MySQL Workbench lets users
manage database design & modeling, SQL development (replacing
MySQL Query Browser) and 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.
The create user statement will create a new Mysql user account. But it have no
privileges. To create user you must have create user privilege or insert privilege for
mysql Database.
Create user ‘username’@’servername’ identified by ‘Password’;
The Drop user statement will drop one or more user accounts and their
privileges.to use this statement you must have global create privileges or delete
privilege for the mysql database.
Drop user ‘username’@’servername’;
The Grant statement grant privileges to the Mysql user account.to use grant
you must have the grant privilege or the privilege that you are granting.
Note: if the username describe in the grant option does not already exist.grant
may create it under the describes conditions.
Grant all on * . * to ‘username’@’servername’ ;
Grant select on * . * to ‘username’@’servername’ ;
Grant select on DB.* to ‘username’@’servername’ ;
Grant select, insert on DB.TB1 to ‘username’@’servername’ ;
Grant insert (c1,c2) on DB.TB1 to ‘username’@’servername’ ;
The Rename user statement rename the existing Mysql accounts.to use it you
must have the global create privilege or update privilege for Mysql Database.
An error occurs if any old account does not exist or any new account exists.
Rename cause the privileges held by the old user to be those held by new user.
Rename user does not drop or invalidate the databases or object s within them
created by the old user
Rename user ‘Existing name’@’servername’ to ‘new name’@’servername’;
The Revoke statement enable administrators to revoke
privileges from MySQL users.
To use the revoke statement you must have the grant
option and the privilege that you are revoking
Revoke all privileges, grant option from ‘user’@
’servername’;
Revoke select on * . * from ‘user’@ ’servername’;
Set Password statement is used to assign password to the existing
Mysql users
If the password is specified using the password function the password is given to the
function as argument,wwhich hash the password and return the encrypted password
 SQL stands for Structured Query Language.
 It is the most commonly used relational database language today.
 SQL works with a variety of different programming languages, such
as Visual Basic.
 Includes data definition language (DDL), statements that specify
and modify database schemas.
 Includes a data manipulation language (DML), statements that
manipulate database content.
 SQL data is case-sensitive, SQL commands are not.
 SQL Must be embedded in a programming language, or used with a
Programming like VB
 SQL is a free form language so there is no limit to the the number of
words per line or fixed line break.
 Syntax statements, words or phrases are always in lower case; keywords
are in uppercase.
Not all versions are case sensitive!
CREATE TABLE: used to create a table.
ALTER TABLE: modifies a table after it was created.
DROP TABLE: removes a table from a database.
INSERT: adds new rows to a table.
UPDATE: modifies one or more attributes.
DELETE: deletes one or more rows from a table.
Things to consider before you create your table are:
The type of data.
The table name.
What column(s) will make up the primary key.
The names of the columns.
CREATE TABLE <table name>
( field1 datatype ( NOT NULL ), key type(optional)
field2 datatype ( NOT NULL ) );
To add or drop columns on existing tables.
ALTER TABLE <table name>
ADD attribute data type;
Or Modify attribute data type;
or
DROP COLUMN attribute;
Drop Table statement Has two options:
Specifies that any foreign key constraint violations that are
caused by dropping the table will cause the corresponding rows of the
related table to be deleted.
blocks the deletion of the table of any foreign key constraint
violations would be created.
DROP TABLE <table name> [ RESTRICT|CASCADE ];
Create table Departments
(id int not NULL primary key auto_increment,
Department char(15));
ALTER table Departments
Add batch varchar (20);
ALTER table Departments
Drop Column batch;
Drop TABLE Departments;
To insert a row into a table, it is necessary to have a value for
each attribute, and order matters.
Insert into Table(Attr1, Attr1, Attr1)values(NULL,’value1’,’value2’);
Insert into Departments(id, Department, Batch) values(NULL,’IT’,’5’);
To update the content of the table:
UPDATE <table name> SET <attr> = <value>
WHERE <selection condition>;
update Departments SET Batch=20 WHERE id=‘2’
Departments=‘physics’;
To delete rows from the table:
DELETE FROM <table name>
WHERE <condition>;
DELETE FROM Departments WHERE id=‘2’;
A basic SELECT statement includes 3 clauses
SELECT <attribute name> FROM <tables> WHERE <condition>
Specifies the
attributes that
are part of the
resulting relation
Specifies the
tables that serve
as the input to the
statement
Specifies the
selection condition,
including the join
condition.
Using a * in a select statement indicates that every attribute of the
input table is to be selected.
Example: SELECT * FROM Departments;
To get unique rows, type the keyword DISTINCT after SELECT.
Example: SELECT DISTINCT batch from Departments
 Where clause is used to retrieve data from the table conditionally.it can
appear only after FROM clause.
Select Column From Table Where Condition;
Select * From Departments Where Batch=‘5’;
A join can be specified in the FROM clause which list the two
input relations and the WHERE clause which lists the join condition.
Students Departments
inner join = join
Select * from Department join student on id=dept_id;
left outer join = left join
Select * from Department left join student on id=dept_id;
right outer join = right join
Select * from Department right join student on id=dept _ id;
Pattern matching selection
Select * from Table where column like condition;
Select * from Departments where id like ‘%5’;
Select * from Departments where id like ‘_5’;
Ordered result selection
1) desc (descending order)
SELECT *
FROM departments
order by Batch desc;
2) asc (ascending order)
SELECT *
FROM departments
order by Batch asc;
The function to divide the tuples into groups and returns an aggregate
for each group.
Usually, it is an aggregate function’s companion
SELECT Batch, sum(Batch) as totalpatch
FROM Departments
group by Batch;
The substitute of WHERE for aggregate functions
Usually, it is an aggregate function’s companion
Example:
SELECT Batch, sum(Batch) as totalBatch
FROM Departments
group by Batch
having sum(Batch) > 10;
COUNT(attr):
Select COUNT(distinct departments) from Departments;
SUM(attr):
Select sum(Batch) from
Departments;
MAX(attr):
Select max(Batch) from
Departments;
Select MIN(Batch) from
Departments;
Select AVG(Batch) from
Departments;
• PHP has the ability to access and manipulate any database that is
ODBC compliant
• PHP includes functionality that allows you to work directly with
different types of databases, without going through ODBC
 Open a connection to a MySQL database server with the
mysql_connect() function
 The mysql_connect() function returns a positive integer if it connects to
the database successfully or FALSE if it does not
 Assign the return value from the mysql_connect() function to a variable
that you can use to access the database in your script
 Close a connection to MySQL database server with the mysql_close()
function
The syntax for the mysql_connect()function is:
$connection = mysql_connect("host" , "user", "password");
if(!$connection)
{
die("Database connection filed: " .mysql_error());
}
The host argument specifies the host name or the where your MySQL
database server is installed
The user and pass arguments specify a MySQL account name and
password
This is also the syntax of connection
<?php
mysql_connect(“servername",“user",“password");
mysql_select_db (“database");
?>
This is also the syntax of connection
<?php
$server="localhost";
$user="root";
$pass=“password";
$database="school";
mysql_connect ($server , $user , $pass);
mysql_select _ db ($database);
?>
 The connection will be closed automatically when the script ends.
 To close the connection before, use the mysqli_close() function
<?php
$con=mysql_connect(“local host", “user", “password");
if (!$con)
{
echo "Failed to connect to MySQL: " . mysql_error();
}
mysqli_close($con);
?>
Reasons for not connecting to a database server include:
 The database server is not running
 Insufficient privileges to access the data source
 Invalid username and/or password
The mysql_errno() and mysql_error() fuction used to show error
The mysql_errno() and mysql_error() functions return the results of
the previous mysql() function
The mysql_errno() function returns the error code from the last attempted
MySQL function call or 0 if no error occurred
<?php
$con = mysql_connect("localhost","root","Rashid0300");
if (!$con)
{ die('Could not connect: ' . mysql_errno()); }
mysql_close($con);
?>
The mysql_error() — Returns the text of the error message from previous
MySQL operation
<?php
$con = mysql_connect("localhost","root","Rashid0300");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_close($con);
?>
The syntax for the mysql_select_db() function is:
◦ mysql_select_db(database , connection);
The function returns a value of true if it successfully selects a database
or false if it does not
<?php
$db_select= mysql_select_db("WIDGET_CORP",$connection);
if(!$db_select)
{ die("Database not found: " .mysql_error()); }
?>
<?php
$host=‘localhost';
$userName = ‘root';
$password = ‘Rashidnawaz';
$database =‘students';
$link = mysql_connect ($host, $userName, $password );
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
<?php
$link = mysql_connect('localhost', ‘root', ‘Rashid0300');
if (!$link)
{
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected)
{
die ('Can't use Database : ' . mysql_error());
}
?>

More Related Content

PDF
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
PDF
4.2 PHP Function
Jalpesh Vasa
 
PDF
Php introduction
krishnapriya Tadepalli
 
PDF
Php array
Nikul Shah
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
Php tutorial(w3schools)
Arjun Shanka
 
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
4.2 PHP Function
Jalpesh Vasa
 
Php introduction
krishnapriya Tadepalli
 
Php array
Nikul Shah
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Php tutorial(w3schools)
Arjun Shanka
 

What's hot (20)

PDF
Servlet and servlet life cycle
Dhruvin Nakrani
 
PPT
RichControl in Asp.net
Bhumivaghasiya
 
PPT
Css Ppt
Hema Prasanth
 
PPT
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
PPT
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
PPT
Php Presentation
Manish Bothra
 
PDF
Basics of JavaScript
Bala Narayanan
 
ODP
Introduction of Html/css/js
Knoldus Inc.
 
PPT
PHP variables
Siddique Ibrahim
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPT
Java Servlets
BG Java EE Course
 
PPT
Javascript
Manav Prasad
 
PDF
Java threads
Prabhakaran V M
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPTX
Javascript
Nagarajan
 
PPTX
class and objects
Payel Guria
 
PPT
CSS Basics
WordPress Memphis
 
PPT
Introduction to JavaScript (1).ppt
MuhammadRehan856177
 
PPT
Php forms
Anne Lee
 
PPSX
Sessions and cookies
www.netgains.org
 
Servlet and servlet life cycle
Dhruvin Nakrani
 
RichControl in Asp.net
Bhumivaghasiya
 
Css Ppt
Hema Prasanth
 
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Php Presentation
Manish Bothra
 
Basics of JavaScript
Bala Narayanan
 
Introduction of Html/css/js
Knoldus Inc.
 
PHP variables
Siddique Ibrahim
 
Introduction to JavaScript
Andres Baravalle
 
Java Servlets
BG Java EE Course
 
Javascript
Manav Prasad
 
Java threads
Prabhakaran V M
 
Event In JavaScript
ShahDhruv21
 
Javascript
Nagarajan
 
class and objects
Payel Guria
 
CSS Basics
WordPress Memphis
 
Introduction to JavaScript (1).ppt
MuhammadRehan856177
 
Php forms
Anne Lee
 
Sessions and cookies
www.netgains.org
 
Ad

Viewers also liked (11)

PDF
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Hipot Studio
 
PPT
Php Coding Convention
Phuong Vy
 
ODP
Coding In Php
Harit Kothari
 
PPT
php 2 Function creating, calling, PHP built-in function
tumetr1
 
PPSX
PHP Comprehensive Overview
Mohamed Loey
 
PDF
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
ODP
PHP Web Programming
Muthuselvam RS
 
PPT
Class 6 - PHP Web Programming
Ahmed Swilam
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
PDF
Introduction to PHP
Bradley Holt
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Hipot Studio
 
Php Coding Convention
Phuong Vy
 
Coding In Php
Harit Kothari
 
php 2 Function creating, calling, PHP built-in function
tumetr1
 
PHP Comprehensive Overview
Mohamed Loey
 
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
PHP Web Programming
Muthuselvam RS
 
Class 6 - PHP Web Programming
Ahmed Swilam
 
Class 3 - PHP Functions
Ahmed Swilam
 
Introduction to PHP
Bradley Holt
 
Introduction to PHP
Jussi Pohjolainen
 
Ad

Similar to PHP FUNCTIONS (20)

PPTX
Learn PHP Lacture2
ADARSH BHATT
 
PPT
Download It
webhostingguy
 
PDF
Php summary
Michelle Darling
 
PPT
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
PDF
Php my sql programing - brochure
Zabeel Institute
 
ODP
Php modul-3
Kristophorus Hadiono
 
PPTX
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
PPTX
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
PPSX
Php session
argusacademy
 
PDF
MySQL for beginners
Saeid Zebardast
 
PPTX
Php mysql online training
GoLogica Technologies
 
PDF
Presenter manual php and mysql with cms (specially for summer interns)
XPERT INFOTECH
 
ODP
PHP BASIC PRESENTATION
krutitrivedi
 
PPT
My sql with querys
NIRMAL FELIX
 
PPT
qwe.ppt
Heru762601
 
Learn PHP Lacture2
ADARSH BHATT
 
Download It
webhostingguy
 
Php summary
Michelle Darling
 
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
Php my sql programing - brochure
Zabeel Institute
 
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
Php session
argusacademy
 
MySQL for beginners
Saeid Zebardast
 
Php mysql online training
GoLogica Technologies
 
Presenter manual php and mysql with cms (specially for summer interns)
XPERT INFOTECH
 
PHP BASIC PRESENTATION
krutitrivedi
 
My sql with querys
NIRMAL FELIX
 
qwe.ppt
Heru762601
 

More from Zeeshan Ahmed (15)

PPTX
Rm presentation on research paper
Zeeshan Ahmed
 
PPTX
Dataware case study
Zeeshan Ahmed
 
DOCX
Project of management
Zeeshan Ahmed
 
PDF
Managemet project fall 2012
Zeeshan Ahmed
 
DOCX
Project of management
Zeeshan Ahmed
 
PPTX
3 ds max
Zeeshan Ahmed
 
PPSX
Macromedia flash presentation2
Zeeshan Ahmed
 
DOCX
Assignment for sociology it 003 to 020
Zeeshan Ahmed
 
DOCX
Education as institutions
Zeeshan Ahmed
 
DOC
Family as an instution
Zeeshan Ahmed
 
DOCX
Marriage
Zeeshan Ahmed
 
DOCX
Religion as institution
Zeeshan Ahmed
 
DOCX
Political institutions
Zeeshan Ahmed
 
PPTX
E transaction
Zeeshan Ahmed
 
PPTX
Html5
Zeeshan Ahmed
 
Rm presentation on research paper
Zeeshan Ahmed
 
Dataware case study
Zeeshan Ahmed
 
Project of management
Zeeshan Ahmed
 
Managemet project fall 2012
Zeeshan Ahmed
 
Project of management
Zeeshan Ahmed
 
3 ds max
Zeeshan Ahmed
 
Macromedia flash presentation2
Zeeshan Ahmed
 
Assignment for sociology it 003 to 020
Zeeshan Ahmed
 
Education as institutions
Zeeshan Ahmed
 
Family as an instution
Zeeshan Ahmed
 
Marriage
Zeeshan Ahmed
 
Religion as institution
Zeeshan Ahmed
 
Political institutions
Zeeshan Ahmed
 
E transaction
Zeeshan Ahmed
 

Recently uploaded (20)

PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
Landforms and landscapes data surprise preview
jpinnuck
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 

PHP FUNCTIONS

  • 2. •Functions in PHP •PHP Form •Post And Get Method •Usage of PHPMYADMIN •Making Database •MYSQL •PHP data base connectivity
  • 3. Functions are the group of statements that you can execute as a single unit. Function definations are the lines of code that make up a function The syntax for defining a function is: <?php function name function(parameters) { statements;} ?> There are two types of functions. 1. Built-in functions. 2. User defined functions.
  • 4. PHP has lots of built-in functions that we use all the time. Some of the function are given below: •PHP Array Functions •PHP Calendar Functions •PHP File System Functions •PHP MySQL Functions •Math functions
  • 5. These functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables. Some Array Functions are: Array(), Array push(), Array pop() etc. <html> <body> <?php $cars=array("Volvo","BMW","Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?> </body> </html>
  • 7. The calendar extension presents a series of functions to simplify converting between different calendar formats. Some PHP Calendar Functions are: Cal info(), Cal days in month() etc. <html> <body> <?php print_r(cal_info(0)); ?> </body> </html>
  • 8. <html> <body> <?php $d=cal_days_in_month(CAL_GREGORIAN,2,1965); echo "There was $d days in February 1965.<br>"; $d=cal_days_in_month(CAL_GREGORIAN,2,2004); echo "There was $d days in February 2004."; ?> </body> </html>
  • 9. The filesystem functions are used to access and manipulate the filesystem PHP provides you all the posible functions you may need to manipulate a file. List: Copy(), delete(), file(), filetype() etc
  • 10. These are functions dealing with MySQL handling and logging or to control the MySQL through PHP functions. List: mysql_close(), mysql_connect() etc. <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?>
  • 11. The math functions can handle values within the range of integer and float types. List: hexdec(), sqrt(), sin() etc <?php echo hexdec("1e") . "<br>"; echo hexdec("a") . "<br>"; echo hexdec("11ff") . "<br>"; echo hexdec("cceeff"); ?>
  • 12. <?php echo(sqrt(0) . "<br>"); echo(sqrt(1) . "<br>"); echo(sqrt(9) . "<br>"); echo(sqrt(0.64) . "<br>"); echo(sqrt(-9)); ?> <?php echo(sin(3) . "<br>"); echo(sin(-3) . "<br>"); echo(sin(0) . "<br>"); echo(sin(M_PI) . "<br>"); echo(sin(M_PI_2));
  • 13. A user defined function is a user-defined set of commands that are carried out when the function is called. Function functionName() { code to be executed; } •A function should start with keyword function and all the function code should be put inside { and } brace. •A function name can start with a letter or underscore not a number. •The function names are case-insensitive.
  • 14. •Information can be passed to functions through arguments. An argument is just like a variable. •Arguments are specified after the function name, inside the parentheses. •You can add as many arguments as you want, just separate them with a comma.
  • 15. <?php function say_hello() { echo “<p>Hello everybody!</p>”; } say_hello(); Function writeMSg() { Echo “How are You?”; } writeMsg(); ?>
  • 16. <?php function familyName($fname) { echo "$fname Refsnes.<br>"; } familyName("Jani"); familyName("Hege"); familyName("Kai Jim"); familyName("Borge"); ?>
  • 17. <?php function familyName($fname,$year) { echo “Name of Person is $fname. Born in $year <br>"; } familyName(“Zeeshan Ahmed","1993"); familyName(“Abdul wahab","1992"); familyName(“Rashid Nawaz","1993"); familyName(“Saad Sattar","1991") ?>
  • 18. If we call the function setHeight() without arguments it takes the default value as argument: <?php function setHeight($minheight=50) { echo "The height is : $minheight <br>"; } setHeight(350); setHeight(); // will use the default value of 50 setHeight(135); setHeight(80); ?>
  • 19. When you create a form you have two choices for the METHOD attribute. You can use one of the following two methods to pass information between pages. • GET method • POST method They both pass the data entered into the form along with the form field name to the web server.
  • 20. Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). GET also has limits on the amount of information to send. The limitation is about 2000 characters. However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. GET should NEVER be used for sending passwords or other sensitive information!
  • 21. <html> <body> <form action="welcome_get.php" method="get"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
  • 22.  Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request) and has no limits on the amount of information to send.  However, because the variables are not displayed in the URL, it is not possible to bookmark the page.  Developers prefer POST for sending form data.
  • 23. <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>
  • 24.  Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3, ...)). This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user.  Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.  $_GET is an array of variables passed to the current script via the URL parameters.  $_POST is an array of variables passed to the current script via the HTTP POST method.
  • 25. •PhpMyAdmin is a handy, graphical administration tool written in php for creating and managing MySQL databases , using a web user interface. •The interface is straight-forward and easy to learn and it allows users to execute SQL queries manually. •It is also open source, so you can download and use it for free.
  • 26. •Create, drop, browse and modify databases. •Perform maintenance on databases. •Run query operations, drop, create, update, check, repair tables and more. •Manage MySQL users and privileges.
  • 28.  You can access phpMyAdmin directly visiting the following URL;  http://localhost/phpMyAdmin Or your server ip address http://127.0.01/phpmyadmin
  • 34. MySQL also called "My Sequel" is the world's second most widely used open-source relational database management system (RDBMS). MySQL is a relational database management system (RDBMS), with no GUI tools to administer MySQL databases or manage data contained within the databases. Users may use the included command line tools, or use MySQL "front- ends", desktop software and web applications that create and manage MySQL databases, build database structures, back up data, and work with data records. The official set of MySQL front-end tools, MySQL Workbench is actively developed by Oracle, and is freely available for use.
  • 35.  The official MySQlworkbench is a free integrated environment developed by MySQL , that enables users to graphically administer MySQL databases and visually design database structures. MySQL Workbench replaces the previous package of software, MYSQL GUI Table. Similar to other third-party packages, but still considered the authoritative MySQL front end, MySQL Workbench lets users manage database design & modeling, SQL development (replacing MySQL Query Browser) and 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.
  • 36. The create user statement will create a new Mysql user account. But it have no privileges. To create user you must have create user privilege or insert privilege for mysql Database. Create user ‘username’@’servername’ identified by ‘Password’; The Drop user statement will drop one or more user accounts and their privileges.to use this statement you must have global create privileges or delete privilege for the mysql database. Drop user ‘username’@’servername’;
  • 37. The Grant statement grant privileges to the Mysql user account.to use grant you must have the grant privilege or the privilege that you are granting. Note: if the username describe in the grant option does not already exist.grant may create it under the describes conditions. Grant all on * . * to ‘username’@’servername’ ; Grant select on * . * to ‘username’@’servername’ ; Grant select on DB.* to ‘username’@’servername’ ; Grant select, insert on DB.TB1 to ‘username’@’servername’ ; Grant insert (c1,c2) on DB.TB1 to ‘username’@’servername’ ;
  • 38. The Rename user statement rename the existing Mysql accounts.to use it you must have the global create privilege or update privilege for Mysql Database. An error occurs if any old account does not exist or any new account exists. Rename cause the privileges held by the old user to be those held by new user. Rename user does not drop or invalidate the databases or object s within them created by the old user Rename user ‘Existing name’@’servername’ to ‘new name’@’servername’;
  • 39. The Revoke statement enable administrators to revoke privileges from MySQL users. To use the revoke statement you must have the grant option and the privilege that you are revoking Revoke all privileges, grant option from ‘user’@ ’servername’; Revoke select on * . * from ‘user’@ ’servername’;
  • 40. Set Password statement is used to assign password to the existing Mysql users If the password is specified using the password function the password is given to the function as argument,wwhich hash the password and return the encrypted password
  • 41.  SQL stands for Structured Query Language.  It is the most commonly used relational database language today.  SQL works with a variety of different programming languages, such as Visual Basic.  Includes data definition language (DDL), statements that specify and modify database schemas.  Includes a data manipulation language (DML), statements that manipulate database content.  SQL data is case-sensitive, SQL commands are not.
  • 42.  SQL Must be embedded in a programming language, or used with a Programming like VB  SQL is a free form language so there is no limit to the the number of words per line or fixed line break.  Syntax statements, words or phrases are always in lower case; keywords are in uppercase. Not all versions are case sensitive!
  • 43. CREATE TABLE: used to create a table. ALTER TABLE: modifies a table after it was created. DROP TABLE: removes a table from a database. INSERT: adds new rows to a table. UPDATE: modifies one or more attributes. DELETE: deletes one or more rows from a table.
  • 44. Things to consider before you create your table are: The type of data. The table name. What column(s) will make up the primary key. The names of the columns. CREATE TABLE <table name> ( field1 datatype ( NOT NULL ), key type(optional) field2 datatype ( NOT NULL ) );
  • 45. To add or drop columns on existing tables. ALTER TABLE <table name> ADD attribute data type; Or Modify attribute data type; or DROP COLUMN attribute;
  • 46. Drop Table statement Has two options: Specifies that any foreign key constraint violations that are caused by dropping the table will cause the corresponding rows of the related table to be deleted. blocks the deletion of the table of any foreign key constraint violations would be created. DROP TABLE <table name> [ RESTRICT|CASCADE ];
  • 47. Create table Departments (id int not NULL primary key auto_increment, Department char(15)); ALTER table Departments Add batch varchar (20); ALTER table Departments Drop Column batch; Drop TABLE Departments;
  • 48. To insert a row into a table, it is necessary to have a value for each attribute, and order matters. Insert into Table(Attr1, Attr1, Attr1)values(NULL,’value1’,’value2’); Insert into Departments(id, Department, Batch) values(NULL,’IT’,’5’);
  • 49. To update the content of the table: UPDATE <table name> SET <attr> = <value> WHERE <selection condition>; update Departments SET Batch=20 WHERE id=‘2’ Departments=‘physics’;
  • 50. To delete rows from the table: DELETE FROM <table name> WHERE <condition>; DELETE FROM Departments WHERE id=‘2’;
  • 51. A basic SELECT statement includes 3 clauses SELECT <attribute name> FROM <tables> WHERE <condition> Specifies the attributes that are part of the resulting relation Specifies the tables that serve as the input to the statement Specifies the selection condition, including the join condition.
  • 52. Using a * in a select statement indicates that every attribute of the input table is to be selected. Example: SELECT * FROM Departments; To get unique rows, type the keyword DISTINCT after SELECT. Example: SELECT DISTINCT batch from Departments
  • 53.  Where clause is used to retrieve data from the table conditionally.it can appear only after FROM clause. Select Column From Table Where Condition; Select * From Departments Where Batch=‘5’;
  • 54. A join can be specified in the FROM clause which list the two input relations and the WHERE clause which lists the join condition. Students Departments
  • 55. inner join = join Select * from Department join student on id=dept_id;
  • 56. left outer join = left join Select * from Department left join student on id=dept_id;
  • 57. right outer join = right join Select * from Department right join student on id=dept _ id;
  • 58. Pattern matching selection Select * from Table where column like condition; Select * from Departments where id like ‘%5’; Select * from Departments where id like ‘_5’;
  • 59. Ordered result selection 1) desc (descending order) SELECT * FROM departments order by Batch desc; 2) asc (ascending order) SELECT * FROM departments order by Batch asc;
  • 60. The function to divide the tuples into groups and returns an aggregate for each group. Usually, it is an aggregate function’s companion SELECT Batch, sum(Batch) as totalpatch FROM Departments group by Batch;
  • 61. The substitute of WHERE for aggregate functions Usually, it is an aggregate function’s companion Example: SELECT Batch, sum(Batch) as totalBatch FROM Departments group by Batch having sum(Batch) > 10;
  • 62. COUNT(attr): Select COUNT(distinct departments) from Departments; SUM(attr): Select sum(Batch) from Departments; MAX(attr): Select max(Batch) from Departments;
  • 63. Select MIN(Batch) from Departments; Select AVG(Batch) from Departments;
  • 64. • PHP has the ability to access and manipulate any database that is ODBC compliant • PHP includes functionality that allows you to work directly with different types of databases, without going through ODBC
  • 65.  Open a connection to a MySQL database server with the mysql_connect() function  The mysql_connect() function returns a positive integer if it connects to the database successfully or FALSE if it does not  Assign the return value from the mysql_connect() function to a variable that you can use to access the database in your script  Close a connection to MySQL database server with the mysql_close() function
  • 66. The syntax for the mysql_connect()function is: $connection = mysql_connect("host" , "user", "password"); if(!$connection) { die("Database connection filed: " .mysql_error()); } The host argument specifies the host name or the where your MySQL database server is installed The user and pass arguments specify a MySQL account name and password
  • 67. This is also the syntax of connection <?php mysql_connect(“servername",“user",“password"); mysql_select_db (“database"); ?>
  • 68. This is also the syntax of connection <?php $server="localhost"; $user="root"; $pass=“password"; $database="school"; mysql_connect ($server , $user , $pass); mysql_select _ db ($database); ?>
  • 69.  The connection will be closed automatically when the script ends.  To close the connection before, use the mysqli_close() function <?php $con=mysql_connect(“local host", “user", “password"); if (!$con) { echo "Failed to connect to MySQL: " . mysql_error(); } mysqli_close($con); ?>
  • 70. Reasons for not connecting to a database server include:  The database server is not running  Insufficient privileges to access the data source  Invalid username and/or password The mysql_errno() and mysql_error() fuction used to show error The mysql_errno() and mysql_error() functions return the results of the previous mysql() function
  • 71. The mysql_errno() function returns the error code from the last attempted MySQL function call or 0 if no error occurred <?php $con = mysql_connect("localhost","root","Rashid0300"); if (!$con) { die('Could not connect: ' . mysql_errno()); } mysql_close($con); ?>
  • 72. The mysql_error() — Returns the text of the error message from previous MySQL operation <?php $con = mysql_connect("localhost","root","Rashid0300"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_close($con); ?>
  • 73. The syntax for the mysql_select_db() function is: ◦ mysql_select_db(database , connection); The function returns a value of true if it successfully selects a database or false if it does not <?php $db_select= mysql_select_db("WIDGET_CORP",$connection); if(!$db_select) { die("Database not found: " .mysql_error()); } ?>
  • 74. <?php $host=‘localhost'; $userName = ‘root'; $password = ‘Rashidnawaz'; $database =‘students'; $link = mysql_connect ($host, $userName, $password ); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?>
  • 75. <?php $link = mysql_connect('localhost', ‘root', ‘Rashid0300'); if (!$link) { die('Not connected : ' . mysql_error()); } $db_selected = mysql_select_db('foo', $link); if (!$db_selected) { die ('Can't use Database : ' . mysql_error()); } ?>