SlideShare une entreprise Scribd logo
1  sur  75
•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.
 You can access phpMyAdmin directly visiting the following URL;
 http://localhost/phpMyAdmin
Or your server ip address
http://127.0.01/phpmyadmin
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());
}
?>

Contenu connexe

Tendances (20)

javascript objects
javascript objectsjavascript objects
javascript objects
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Web Development using HTML & CSS
Web Development using HTML & CSSWeb Development using HTML & CSS
Web Development using HTML & CSS
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Js ppt
Js pptJs ppt
Js ppt
 
Files in php
Files in phpFiles in php
Files in php
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operators
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 

En vedette

Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyAnonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyHipot Studio
 
Php Coding Convention
Php Coding ConventionPhp Coding Convention
Php Coding ConventionPhuong Vy
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in functiontumetr1
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive OverviewMohamed Loey
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingAhmed Swilam
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 

En vedette (11)

Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyAnonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
 
Php Coding Convention
Php Coding ConventionPhp Coding Convention
Php Coding Convention
 
Coding In Php
Coding In PhpCoding In Php
Coding In Php
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similaire à PHP FUNCTIONS

Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolmentRajib Ahmed
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)ÇözümPARK
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGiuliano Iacobelli
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesDoris Chen
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptxMattMarino13
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Mindfire Solutions
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 

Similaire à PHP FUNCTIONS (20)

Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
PPT
PPTPPT
PPT
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 

Plus de Zeeshan Ahmed

Rm presentation on research paper
Rm presentation on research paperRm presentation on research paper
Rm presentation on research paperZeeshan Ahmed
 
Dataware case study
Dataware case study Dataware case study
Dataware case study Zeeshan Ahmed
 
Project of management
Project of managementProject of management
Project of managementZeeshan Ahmed
 
Managemet project fall 2012
Managemet project fall 2012Managemet project fall 2012
Managemet project fall 2012Zeeshan Ahmed
 
Project of management
Project of managementProject of management
Project of managementZeeshan Ahmed
 
Macromedia flash presentation2
Macromedia flash presentation2Macromedia flash presentation2
Macromedia flash presentation2Zeeshan Ahmed
 
Assignment for sociology it 003 to 020
Assignment for sociology it  003 to 020Assignment for sociology it  003 to 020
Assignment for sociology it 003 to 020Zeeshan Ahmed
 
Education as institutions
Education as institutionsEducation as institutions
Education as institutionsZeeshan Ahmed
 
Family as an instution
Family as an instutionFamily as an instution
Family as an instutionZeeshan Ahmed
 
Religion as institution
Religion as institutionReligion as institution
Religion as institutionZeeshan Ahmed
 
Political institutions
Political institutionsPolitical institutions
Political institutionsZeeshan Ahmed
 

Plus de Zeeshan Ahmed (15)

Rm presentation on research paper
Rm presentation on research paperRm presentation on research paper
Rm presentation on research paper
 
Dataware case study
Dataware case study Dataware case study
Dataware case study
 
Project of management
Project of managementProject of management
Project of management
 
Managemet project fall 2012
Managemet project fall 2012Managemet project fall 2012
Managemet project fall 2012
 
Project of management
Project of managementProject of management
Project of management
 
3 ds max
3 ds max3 ds max
3 ds max
 
Macromedia flash presentation2
Macromedia flash presentation2Macromedia flash presentation2
Macromedia flash presentation2
 
Assignment for sociology it 003 to 020
Assignment for sociology it  003 to 020Assignment for sociology it  003 to 020
Assignment for sociology it 003 to 020
 
Education as institutions
Education as institutionsEducation as institutions
Education as institutions
 
Family as an instution
Family as an instutionFamily as an instution
Family as an instution
 
Marriage
MarriageMarriage
Marriage
 
Religion as institution
Religion as institutionReligion as institution
Religion as institution
 
Political institutions
Political institutionsPolitical institutions
Political institutions
 
E transaction
E transactionE transaction
E transaction
 
Html5
Html5Html5
Html5
 

Dernier

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Dernier (20)

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

PHP FUNCTIONS

  • 1.
  • 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.
  • 27.
  • 28.  You can access phpMyAdmin directly visiting the following URL;  http://localhost/phpMyAdmin Or your server ip address http://127.0.01/phpmyadmin
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 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()); } ?>