SlideShare a Scribd company logo
1 of 53
Download to read offline
PHP and MySQL : Server Side
Scripting For Web Development
View PHP & MYSQL Course at: http://www.edureka.co/php-mysql
For more details please contact us:
US : 1800 275 9730 (toll free)
INDIA : +91 88808 62004
Email Us : sales@edureka.co
For Queries:
Post on Twitter @edurekaIN: #askEdureka
Post on Facebook /edurekaIN
Slide 2 http://www.edureka.co/php-mysql
Objectives
At the end of this module, you will be able to understand:
 Basics of PHP
 Conditional Logic and Loops
 PHP Form Handling
 PHP Functions
 Object Oriented Concepts
 Implement MySQL with PHP
Slide 3 http://www.edureka.co/php-mysql
PHP & MySQL - Overview
 PHP & MySQL is an open-source
 PHP & MySQL are two key components in the open-source LAMP stack
 It is the most appropriate tool for developing dynamic web pages. For example, we can develop informative forums,
chatting platforms, e-commerce shopping carts, CRM solutions, community websites and database driven sites
 PHP with MySQL is a powerful combination showing the real power of Server-Side scripting
 PHP has a wide range of MySQL functions available with the help of a separate module
Slide 4 http://www.edureka.co/php-mysql
Benefits of PHP & MySQL
PHP web development means developing websites and dynamic web pages using the versatile and capable server-side
scripting language
CAPABLE
PLATFORM
INDEPENDENT
SUPPORTS ALL
MAJOR WEB
SERVERS
SUPPORTS ALL
MAJOR DATABASES
FREE OF
COST
FASTER
DEVELOPMENTS
LARGE
COMMUNITIES
EASY
PROVEN AND
TRUSTED
SECURE
Slide 5 http://www.edureka.co/php-mysql
Intricacies of PHP & MySQL
Dynamic and Weak Typing
Variable Variables
Dynamic Arrays
Dynamic Constants
Dynamic Functions
Dynamic Code
Dynamic Includes
Built-in Functions
Superglobals
Slide 6 http://www.edureka.co/php-mysql
What is PHP?
 PHP is the web development language written by and for web developers.
 PHP stands for Hypertext Preprocessor.
 It was originally named as Personal Home Page Tools and later on as Professional Home Page.
 It is a server-side script, which can be embedded in HTML or used as a standalone program script.
Slide 7 http://www.edureka.co/php-mysql
Script in PHP
 PHP can be embedded in HTML or can be written as stand-alone program by using special markup tags. They are:
<?php
//PHP code comes here
?>
 We can write PHP script in always available Notepad or get some PHP specific IDE downloaded from internet.
 We can call the file from web browser after saving it using .php extension in webserver directory.
Slide 8 http://www.edureka.co/php-mysql
PHP Example
<html>
<head>
<title>PHP Example</title>
<body>
<?php echo “This is my first PHP script."; ?>
</body>
</html>
 The rendered HTML of the above script looks like below:
<html>
<head>
<title>PHP Example</title>
<body>
<p> This is my first PHP script.</p>
</body>
</html>
Slide 9 http://www.edureka.co/php-mysql
Environment Setup
 To execute PHP script we need three components to be installed on our computer:
 Web Server - PHP supports many web server, including Apache server and IIS.
 Database - PHP supports many databases. But the extensively used is MySQL.
 PHP Parser - A Parser is required to generate HTML output from PHP code.
Slide 10 http://www.edureka.co/php-mysql
PHP Variables
 A variable in any programming language is a name to store a value that can be referenced later as required.
 In PHP, Variables are defined a name preceded by a dollar sign ($). Eg. $firstName, $last_Name etc.
 The type of a variable depends upon the value of its values.
 Equal to (=) operator is used to assign a value to a variable name, on the left-hand side and the value on the
right-hand side.
 In PHP, variables are not required to be declared before assigning a value.
 Data type for a variables is not required to be declared for a variable in PHP. Depending upon the value it is
automatically interpreted.
Slide 11 http://www.edureka.co/php-mysql
Decision Making Statements
 Statements that are used to perform certain functions depending on certain conditions are called Decision
making statements as given below:
• If…else statement
• elseif statement
• Switch statement
Slide 12 http://www.edureka.co/php-mysql
If-else Statement
<?php
If($user == “Mohit”)
{
print “Hello Mohit.”;
}
else
{
print “You are not Mohit.”;
}
?>
Slide 13 http://www.edureka.co/php-mysql
If-elseif Statement
<?php
if($day ==5) {
print(“Five team members. <br>”);
} elseif($day ==4) {
print(“Four team members <br>”);
} elseif($day ==3) {
print(“Three team members <br>”);
} elseif($day ==2) {
print(“Two team members <br>”);
} elseif($day ==1) {
print(“One team members <br>”);
}
?>
Slide 14 http://www.edureka.co/php-mysql
Switch Statement
<?php
switch($day)
{
case 3:
print(“Three golden rings <br>”);
break;
case 2:
print(“Two golden rings <br>”);
break;
default:
print(“One golden ring <br>”);
}
?>
Slide 15 http://www.edureka.co/php-mysql
Looping Statements
 Following are the various looping statements in PHP:
• For loop
• Foreach loop
• While loop
• Do…while loop
Slide 16 http://www.edureka.co/php-mysql
For Statement
 A for statement execution starts with evaluation of initial-expression, which is initialization of counter variable .
 Then evaluation of termination-check is done. if false, the for statement concludes, and if true, the statement
executes.
 Finally, the loop-end-expression is executed and the loop begins again with termination–check.
Example:
<?php
for($counter=1 //initial expression
$counter<4; //termination checks
$counter++ //loop-end expressions) {
print(“$counter<br />”);
}
?>
Result:
1
2
3
Slide 17 http://www.edureka.co/php-mysql
Foreach Statement
 We use foreach loop to iterate through arrays and objects.
Example:
<?php
$months = array(“January", “February", “March", “April“,
”May”, ”June”, ”July”, ”August”, ”September”, ”October”,
”November”, ”December”);
foreach ($months as $value) {
echo "$value <br>";
}
?>
Result:
January
February
March
April
May
June
July
August
September
October
November
December
Slide 18 http://www.edureka.co/php-mysql
While Statement
 The while loop evaluates the condition expression as Boolean. if true, it executes statements and then starts
again by evaluating condition. If the condition is false, the loop terminates.
Example:
<?php
$count=1;
While($counter<=6)
{
print(“Counter value is $counter <br>”);
$counter = $counter++;
}
?>
Result:
Count value is 1
Count value is 2
Count value is 3
Count value is 4
Count value is 5
Count value is 6
Slide 19 http://www.edureka.co/php-mysql
Do-While Statement
 The only difference between while and do-while is that the do-while will execute the statement at least once.
 The statement is executed once, and then the expression is evaluated. If the expression is true, the statement is
repeated until the expression becomes false.
Example:
<?php
$counter=50;
do {
print(“Counter value is $counter. <br>”);
$counter = $counter + 1;
}
While($counter<=10)
?>
Result:
Counter value is 50.
Slide 20 http://www.edureka.co/php-mysql
Break Statement
 The break command exits from the inner most loop statements that contain it.
Example:
<?php
for($x=1; $x<10; $x++) {
If($x % 2 !=0) {
break;
print(“$x “);
}
}
?>
Result:
The above code prints nothing because
1 is odd which terminates the for loop
immediately.
Slide 21 http://www.edureka.co/php-mysql
Continue Statement
 The continue command skips to the end of the current iteration of the innermost loop that contains it.
Example:
<?php
for($x=1; $x<10; $x++) {
if($x % 2 !=0) {
continue;
}
print(“$x “);
}
?>
Result:
2 4 6 8
Here, the continue statement will skip any
of odd numbers. It will print only the even
numbers.
Slide 22 http://www.edureka.co/php-mysql
PHP Forms
 Form is a web page which allows user to enter data.
 Forms contains many elements like text box, text area, checkbox, radio button and submit button
 User enters information in the form elements
 And, the entered information are sent to the server for processing
 Using HTML we can create forms and using PHP we can process form elements
 Let us see an example in the upcoming slides
Slide 23 http://www.edureka.co/php-mysql
HTML Form
 See the below example for HTML form with two text boxes and one submit button
<html>
<body>
<form action=“save.php" method="post">
First Name: <input type="text" name=“firstname"><br>
Last Name: <input type="text" name=“lastname"><br>
<input type="submit">
</form>
</body>
</html>
 The user enters the above information and clicks the submit button, the information is sent to a file called
“save.php”
Slide 24 http://www.edureka.co/php-mysql
Processing Forms
 The form data is sent to a PHP file for processing
 We can send form data to server using two methods
• GET method
• POST method
 In the previous code, we used POST method to send data. See the below example, to display the submitted data.
To print the values, use the below code in save.php
<?php
Your First name is: <?php echo $_POST["firstname"]; ?>
<br>
Your Lastname is: <?php echo $_POST["lastname"]; ?>
?>
Slide 25 http://www.edureka.co/php-mysql
Get Method
 GET method passes argument from one page to the next page.
 It appends the indicated variable name(s) and values(s) to the URL. The value and the page name separated by
question-mark(?)
<form action=“display.php” method=“get”>
Name: <input type=“text” name=“name”><br/>
Email:<input type=“text” name=“email”><br/>
<input type=“submit” value=“submit”>
</form>
<?php
echo “Name: ”.$_GET*‘name’+;
echo “Email: ”.$_GET*‘email’+;
?>
Slide 26 http://www.edureka.co/php-mysql
Get Method (Continued)
 Advantage:
• It constructs an actual new and differentiable URL query string. Users can now bookmark this page
 Disadvantage:
• The GET method is not suitable for logins because the username and password are fully visible onscreen as
well as potentially stored in the client browser’s memory as a visited page
• Every GET submission is recorded in the web server log, data set included
• Because the GET method assigns data to a server environment variable, the length of the URL is limited
Slide 27 http://www.edureka.co/php-mysql
Post Method
 POST is the preferred method of form submission
 The form data is included in the body of the form when it is forwarding to the processing agent. There will be no
change in the URL
<form action=“display.php” method=“post”>
Name: <input type=“text” name=“name”><br/>
Email:<input type=“text” name=“email”><br/>
<input type=“submit” value=“submit”>
</form>
 POST Method data can be accessed using $_POST variable
<?php
echo “Name: ”.$_POST*‘name’+;
echo “Email: ”.$_POST*‘email’+;
?>
Slide 28 http://www.edureka.co/php-mysql
Post Method (Continued)
 Advantages:
• It is more secure than GET because user-entered information is never visible in the URL
• It is much larger limit on the amount of data than can be passed
 Disadvantages:
• The results at a given moment cannot be bookmarked
• This methods can be incompatible with certain firewall setups, which strip the form data as a security
measure
Slide 29 http://www.edureka.co/php-mysql
PHP Functions
 A function is a set of codes which are used to perform some specific tasks
 Its main advantage is reusability. Instead of defining a code repeatedly, we can create functions and use them
when needed
 The function will not execute directly when the program loads. We need to call a function
 There are two types of function available in PHP
• Built-in functions - The real power of PHP is its functions. PHP has more than 1000 built-in functions. They
can be invoked directly
• User defined functions - We can also create our own functions. We will discuss about the creation of our
own functions in next slide
Slide 30 http://www.edureka.co/php-mysql
PHP Functions Syntax
Example:
function functionName() {
set of code to be executed;
}
 Syntax to call a function:
functionName();
 Rules to follow while naming a function:
• Function names are NOT case-sensitive
• Function name starts with a letter or underscore
• Function name cannot start with numbers
Slide 31 http://www.edureka.co/php-mysql
PHP Functions Return Value
 Function can return a value. It will return one value or more than one value using array
 It returns the value using the return keyword. If the return statement is found in the function it will stop
execution and send the value to the callback function.
Slide 32 http://www.edureka.co/php-mysql
Function Parameters
 Function parameters are variables passes to the function inside the parentheses. They are declared much like a
typical variable would be:
<?php
// multiply a value by 10 and return it to the caller
function multiply ($value) {
$value = $value * 10;
return $value;
}
$retval= multiply (10);
Print "Return value is $retvaln";
?>
Slide 33 http://www.edureka.co/php-mysql
Object Oriented Concepts
 Object Oriented Programming (OOP) is a programming concept used to design our application
• Applications can be of any type
• Web based application
• Window based application
• It is used to write programming in object model structure
 Advantages of Object Oriented Programming
• Re-Usability of your code
• Easy to Maintain
• Good Level of Abstraction
Slide 34 http://www.edureka.co/php-mysql
Classes
 Defining PHP Classes
• Class is a user defined data type which includes functions and member variables
• It is used to define object. It is the blueprint of the object
 Class Declaration
• Class is declared using class keyword followed by the name
• A set of braces used to declare variables and functions
• Variables can be declared using var keyword followed by $
<?php
class classname {
var$var1;
var$var2 = "constant text";
function myfunc($arg1, $arg2) {
//function code
}
}
?>
Slide 35 http://www.edureka.co/php-mysql
Creating Objects in PHP
 In Object Oriented language, properties are called member variables. And, behaviors are called member
functions
• Once we defined our class, then we can create as many objects using the new operator
• Pen is class, Hero pen, Reynolds etc are called its objects
 Syntax
$objectname= new classname();
Example:
$hero = new Pen;
$reynolds= new Pen;
Slide 36 http://www.edureka.co/php-mysql
Calling Member Functions
 After creating objects, we can access our member functions
 We can only access the member function of the class of which we created objects
 Let us see how to access member functions using the objects $hero, $reynolds
Example
Assigning values to the object $hero by accessing its member functions
$hero -> setPrice("100"); //assigns value 100 to price variable
$hero -> setColor("Green"); //assigns value green to color variable
$hero -> setType("Ink Pen"); //assigns value Ink Pen to type variable
$hero -> setWritingcolor(“blue”); //assigns value blue to writing color of the pen
Slide 37 http://www.edureka.co/php-mysql
Constructor Functions
 Constructor is a special type of function
 It is automatically invoked when an object is created. So we can use this function for initialization
 To define a constructor, PHP provides a special function called __construct(). We can pass any number of
arguments to this function
 A function can also become a constructor, if it defined by the same name of the class
 Two ways to declare constructors
• __construct() function
• Define function using same class name
Slide 38 http://www.edureka.co/php-mysql
Constructor Functions (Continued)
Method 1:
class classname
{
function __construct(p1, p2, ..., pN]){
/* Class initialization code */
}
}
Method 2:
class classname
{
function classname(p1, p2, ..., pN]){
/* Class initialization code */
}
}
Slide 39 http://www.edureka.co/php-mysql
Inheritance
 Inheritance is the method of inheriting one class properties to other class
 We can achieve this by using ‘extends’ keyword
Class parentclass
{
//parent class definition
}
Class childclass extends parentclass
{
//child class definition
}
Slide 40 http://www.edureka.co/php-mysql
Function Overriding
 Function overriding is nothing but overriding the function of parent class to child class and modify those
functions
 Using overriding, we can alter function definition in child class
 To override, we need to create same function in sub class which it is in base class
Slide 41 http://www.edureka.co/php-mysql
class baseclass {
public function one() {
echo “First function”;
}
public function two() {
echo “second function”;
}
}
class childclass extends baseclass {
function two($text) //overriding function2
{
echo "$text ";
}
}
$text = new childclass();
$text->two("Sachin");//it will print Sachin
Function Overriding
 Example:
Slide 42 http://www.edureka.co/php-mysql
Access Modifiers
 Access modifiers is nothing but the level of access and the visibility of the member variables and member
functions
 We can use this access modifiers to show or hide data
 We have three access modifiers in PHP
• Private
• Protected
• Public
Slide 43 http://www.edureka.co/php-mysql
Final Keyword
 Final is a keyword
 If we define the class as final then we cannot extend the class
 If we declare the method as final we cannot override the method
 Syntax for Defining Function as Final
final public function functioname()
{
//function definition comes here
}
 Syntax for Defining Class as Final
final class classname
{
//class definition comes here
}
Slide 44 http://www.edureka.co/php-mysql
Database
 A database is a unique application that organizes a group of data
 Each database application has one or more APIs for creating, managing, accessing, searching and duplicating the
data it holds
 Hence, the data can easily be accessed, managed, and updated
Slide 45 http://www.edureka.co/php-mysql
MySQL Introduction
 MySQL is a database system which is used on the web and runs on the server
 It uses standard SQL
 It is very fast, reliable and easy to use and also it is ideal for both small and large applications
Slide 46 http://www.edureka.co/php-mysql
MySQL Connection
 Using PHP Script
• Using mysql_connect() function we can open a database connection
• This function requires five parameters and all are optional
 Syntax
mysql_connect(server,user,pass,new_link,client_flag);
Slide 47 http://www.edureka.co/php-mysql
MySQL Disconnect
 Using PHP Script
• Using mysql_close() function we can disconnect from MySQL server
• This function takes single parameter
 Syntax
mysql_close(resource $link_identifier);
 If we did not specify any parameter then the last opened database is closed
Slide 48 http://www.edureka.co/php-mysql
Execute MySQL Queries
 Using PHP function mysql_query() we can run a MySQL query.
 This function needs two parameters and returns Boolean value
 Function Syntax
mysql_query(sql_query, connection);
 First parameter is mandatory. sql_query parameter is mandatory. It specifies the original query to be executed
 The second parameter is optional. It is the connection parameter. If we did not specified, it takes the last opened
connection
 Consider we are going to create a database ‘student_details’ to store student information
Slide 49 http://www.edureka.co/php-mysql
Fetching Data
 Select Query
• Data Manipulation –Select Query
• Select statement is used to fetch data from the database
• Fetching data can be simple queries or complex queries
 To select data using PHP script, we can use mysql_query() function
• Write the select query inside the mysql_query() function
• This function is used to execute MySQL queries
• To fetch the selected data using select query we can use two functions
mysql_fetch_array()
mysql_fetch_assoc()
Questions
Slide 50 http://www.edureka.co/php-mysqlTwitter @edurekaIN, Facebook /edurekaIN, use #AskEdureka for Questions
Slide 51 http://www.edureka.co/php-mysql
Course Topics
 Module 1
» PHP Basics and Conditional Logic
 Module 2
» Functions and Error Handling
 Module 3
» Object Oriented Programming
 Module 4
» MySQL Installation and Basics
 Module 5
» Advance Queries and Data Manipulation
using PHP
Module 6
» MVC Infrastructure Basics & Introduction to
CakePHP
Module 7
» CakePHP Controller, Views and Layout
 Module 8
» Models and Database Interaction in CakePHP
 Module 9
» Creating Dynamic Forms using CakePHP Html
Helpers
 Module 10
» Using MVC & CakePHP to develop a website
Slide 52
LIVE Online Class
Class Recording in LMS
24/7 Post Class Support
Module Wise Quiz
Project Work
Verifiable Certificate
http://www.edureka.co/php-mysql
How it Works?
PHP and MySQL : Server Side Scripting For Web Development

More Related Content

What's hot

Research in Cloud Computing
Research in Cloud ComputingResearch in Cloud Computing
Research in Cloud Computing
Rajshri Mohan
 

What's hot (20)

Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Dns server
Dns serverDns server
Dns server
 
Introduction to Java -unit-1
Introduction to Java -unit-1Introduction to Java -unit-1
Introduction to Java -unit-1
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP Form Validation Technique
PHP Form Validation TechniquePHP Form Validation Technique
PHP Form Validation Technique
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Document Type Definition (DTD)
Document Type Definition (DTD)Document Type Definition (DTD)
Document Type Definition (DTD)
 
Bootstrap ppt
Bootstrap pptBootstrap ppt
Bootstrap ppt
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Applets
AppletsApplets
Applets
 
PHP-MySQL Database Connectivity Using XAMPP Server
PHP-MySQL Database Connectivity Using XAMPP ServerPHP-MySQL Database Connectivity Using XAMPP Server
PHP-MySQL Database Connectivity Using XAMPP Server
 
URI handlers
URI handlersURI handlers
URI handlers
 
Research in Cloud Computing
Research in Cloud ComputingResearch in Cloud Computing
Research in Cloud Computing
 
File Uploading in PHP
File Uploading in PHPFile Uploading in PHP
File Uploading in PHP
 

Viewers also liked

HIVE: Data Warehousing & Analytics on Hadoop
HIVE: Data Warehousing & Analytics on HadoopHIVE: Data Warehousing & Analytics on Hadoop
HIVE: Data Warehousing & Analytics on Hadoop
Zheng Shao
 

Viewers also liked (11)

Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development  Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
Webinar: PHP and MySQL - Server-side Scripting Language for Web Development
 
CV - Vivek Bajpai
CV - Vivek BajpaiCV - Vivek Bajpai
CV - Vivek Bajpai
 
Big data and APIs for PHP developers - SXSW 2011
Big data and APIs for PHP developers - SXSW 2011Big data and APIs for PHP developers - SXSW 2011
Big data and APIs for PHP developers - SXSW 2011
 
Part 2 - Hadoop Data Loading using Hadoop Tools and ODI12c
Part 2 - Hadoop Data Loading using Hadoop Tools and ODI12cPart 2 - Hadoop Data Loading using Hadoop Tools and ODI12c
Part 2 - Hadoop Data Loading using Hadoop Tools and ODI12c
 
Web Crawling and Data Gathering with Apache Nutch
Web Crawling and Data Gathering with Apache NutchWeb Crawling and Data Gathering with Apache Nutch
Web Crawling and Data Gathering with Apache Nutch
 
Large scale crawling with Apache Nutch
Large scale crawling with Apache NutchLarge scale crawling with Apache Nutch
Large scale crawling with Apache Nutch
 
Why use big data tools to do web analytics? And how to do it using Snowplow a...
Why use big data tools to do web analytics? And how to do it using Snowplow a...Why use big data tools to do web analytics? And how to do it using Snowplow a...
Why use big data tools to do web analytics? And how to do it using Snowplow a...
 
Python in the Hadoop Ecosystem (Rock Health presentation)
Python in the Hadoop Ecosystem (Rock Health presentation)Python in the Hadoop Ecosystem (Rock Health presentation)
Python in the Hadoop Ecosystem (Rock Health presentation)
 
HIVE: Data Warehousing & Analytics on Hadoop
HIVE: Data Warehousing & Analytics on HadoopHIVE: Data Warehousing & Analytics on Hadoop
HIVE: Data Warehousing & Analytics on Hadoop
 
Titan: Big Graph Data with Cassandra
Titan: Big Graph Data with CassandraTitan: Big Graph Data with Cassandra
Titan: Big Graph Data with Cassandra
 
Hadoop demo ppt
Hadoop demo pptHadoop demo ppt
Hadoop demo ppt
 

Similar to PHP and MySQL : Server Side Scripting For Web Development

1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
honey725342
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
Developing web applications
Developing web applicationsDeveloping web applications
Developing web applications
salissal
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
GiyaShefin
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 

Similar to PHP and MySQL : Server Side Scripting For Web Development (20)

1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
 
PHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHPPHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHP
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
 
Phpbasics
PhpbasicsPhpbasics
Phpbasics
 
Developing web applications
Developing web applicationsDeveloping web applications
Developing web applications
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
10_introduction_php.ppt
10_introduction_php.ppt10_introduction_php.ppt
10_introduction_php.ppt
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
php 1
php 1php 1
php 1
 
introduction_php.ppt
introduction_php.pptintroduction_php.ppt
introduction_php.ppt
 

More from Edureka!

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

PHP and MySQL : Server Side Scripting For Web Development

  • 1. PHP and MySQL : Server Side Scripting For Web Development View PHP & MYSQL Course at: http://www.edureka.co/php-mysql For more details please contact us: US : 1800 275 9730 (toll free) INDIA : +91 88808 62004 Email Us : sales@edureka.co For Queries: Post on Twitter @edurekaIN: #askEdureka Post on Facebook /edurekaIN
  • 2. Slide 2 http://www.edureka.co/php-mysql Objectives At the end of this module, you will be able to understand:  Basics of PHP  Conditional Logic and Loops  PHP Form Handling  PHP Functions  Object Oriented Concepts  Implement MySQL with PHP
  • 3. Slide 3 http://www.edureka.co/php-mysql PHP & MySQL - Overview  PHP & MySQL is an open-source  PHP & MySQL are two key components in the open-source LAMP stack  It is the most appropriate tool for developing dynamic web pages. For example, we can develop informative forums, chatting platforms, e-commerce shopping carts, CRM solutions, community websites and database driven sites  PHP with MySQL is a powerful combination showing the real power of Server-Side scripting  PHP has a wide range of MySQL functions available with the help of a separate module
  • 4. Slide 4 http://www.edureka.co/php-mysql Benefits of PHP & MySQL PHP web development means developing websites and dynamic web pages using the versatile and capable server-side scripting language CAPABLE PLATFORM INDEPENDENT SUPPORTS ALL MAJOR WEB SERVERS SUPPORTS ALL MAJOR DATABASES FREE OF COST FASTER DEVELOPMENTS LARGE COMMUNITIES EASY PROVEN AND TRUSTED SECURE
  • 5. Slide 5 http://www.edureka.co/php-mysql Intricacies of PHP & MySQL Dynamic and Weak Typing Variable Variables Dynamic Arrays Dynamic Constants Dynamic Functions Dynamic Code Dynamic Includes Built-in Functions Superglobals
  • 6. Slide 6 http://www.edureka.co/php-mysql What is PHP?  PHP is the web development language written by and for web developers.  PHP stands for Hypertext Preprocessor.  It was originally named as Personal Home Page Tools and later on as Professional Home Page.  It is a server-side script, which can be embedded in HTML or used as a standalone program script.
  • 7. Slide 7 http://www.edureka.co/php-mysql Script in PHP  PHP can be embedded in HTML or can be written as stand-alone program by using special markup tags. They are: <?php //PHP code comes here ?>  We can write PHP script in always available Notepad or get some PHP specific IDE downloaded from internet.  We can call the file from web browser after saving it using .php extension in webserver directory.
  • 8. Slide 8 http://www.edureka.co/php-mysql PHP Example <html> <head> <title>PHP Example</title> <body> <?php echo “This is my first PHP script."; ?> </body> </html>  The rendered HTML of the above script looks like below: <html> <head> <title>PHP Example</title> <body> <p> This is my first PHP script.</p> </body> </html>
  • 9. Slide 9 http://www.edureka.co/php-mysql Environment Setup  To execute PHP script we need three components to be installed on our computer:  Web Server - PHP supports many web server, including Apache server and IIS.  Database - PHP supports many databases. But the extensively used is MySQL.  PHP Parser - A Parser is required to generate HTML output from PHP code.
  • 10. Slide 10 http://www.edureka.co/php-mysql PHP Variables  A variable in any programming language is a name to store a value that can be referenced later as required.  In PHP, Variables are defined a name preceded by a dollar sign ($). Eg. $firstName, $last_Name etc.  The type of a variable depends upon the value of its values.  Equal to (=) operator is used to assign a value to a variable name, on the left-hand side and the value on the right-hand side.  In PHP, variables are not required to be declared before assigning a value.  Data type for a variables is not required to be declared for a variable in PHP. Depending upon the value it is automatically interpreted.
  • 11. Slide 11 http://www.edureka.co/php-mysql Decision Making Statements  Statements that are used to perform certain functions depending on certain conditions are called Decision making statements as given below: • If…else statement • elseif statement • Switch statement
  • 12. Slide 12 http://www.edureka.co/php-mysql If-else Statement <?php If($user == “Mohit”) { print “Hello Mohit.”; } else { print “You are not Mohit.”; } ?>
  • 13. Slide 13 http://www.edureka.co/php-mysql If-elseif Statement <?php if($day ==5) { print(“Five team members. <br>”); } elseif($day ==4) { print(“Four team members <br>”); } elseif($day ==3) { print(“Three team members <br>”); } elseif($day ==2) { print(“Two team members <br>”); } elseif($day ==1) { print(“One team members <br>”); } ?>
  • 14. Slide 14 http://www.edureka.co/php-mysql Switch Statement <?php switch($day) { case 3: print(“Three golden rings <br>”); break; case 2: print(“Two golden rings <br>”); break; default: print(“One golden ring <br>”); } ?>
  • 15. Slide 15 http://www.edureka.co/php-mysql Looping Statements  Following are the various looping statements in PHP: • For loop • Foreach loop • While loop • Do…while loop
  • 16. Slide 16 http://www.edureka.co/php-mysql For Statement  A for statement execution starts with evaluation of initial-expression, which is initialization of counter variable .  Then evaluation of termination-check is done. if false, the for statement concludes, and if true, the statement executes.  Finally, the loop-end-expression is executed and the loop begins again with termination–check. Example: <?php for($counter=1 //initial expression $counter<4; //termination checks $counter++ //loop-end expressions) { print(“$counter<br />”); } ?> Result: 1 2 3
  • 17. Slide 17 http://www.edureka.co/php-mysql Foreach Statement  We use foreach loop to iterate through arrays and objects. Example: <?php $months = array(“January", “February", “March", “April“, ”May”, ”June”, ”July”, ”August”, ”September”, ”October”, ”November”, ”December”); foreach ($months as $value) { echo "$value <br>"; } ?> Result: January February March April May June July August September October November December
  • 18. Slide 18 http://www.edureka.co/php-mysql While Statement  The while loop evaluates the condition expression as Boolean. if true, it executes statements and then starts again by evaluating condition. If the condition is false, the loop terminates. Example: <?php $count=1; While($counter<=6) { print(“Counter value is $counter <br>”); $counter = $counter++; } ?> Result: Count value is 1 Count value is 2 Count value is 3 Count value is 4 Count value is 5 Count value is 6
  • 19. Slide 19 http://www.edureka.co/php-mysql Do-While Statement  The only difference between while and do-while is that the do-while will execute the statement at least once.  The statement is executed once, and then the expression is evaluated. If the expression is true, the statement is repeated until the expression becomes false. Example: <?php $counter=50; do { print(“Counter value is $counter. <br>”); $counter = $counter + 1; } While($counter<=10) ?> Result: Counter value is 50.
  • 20. Slide 20 http://www.edureka.co/php-mysql Break Statement  The break command exits from the inner most loop statements that contain it. Example: <?php for($x=1; $x<10; $x++) { If($x % 2 !=0) { break; print(“$x “); } } ?> Result: The above code prints nothing because 1 is odd which terminates the for loop immediately.
  • 21. Slide 21 http://www.edureka.co/php-mysql Continue Statement  The continue command skips to the end of the current iteration of the innermost loop that contains it. Example: <?php for($x=1; $x<10; $x++) { if($x % 2 !=0) { continue; } print(“$x “); } ?> Result: 2 4 6 8 Here, the continue statement will skip any of odd numbers. It will print only the even numbers.
  • 22. Slide 22 http://www.edureka.co/php-mysql PHP Forms  Form is a web page which allows user to enter data.  Forms contains many elements like text box, text area, checkbox, radio button and submit button  User enters information in the form elements  And, the entered information are sent to the server for processing  Using HTML we can create forms and using PHP we can process form elements  Let us see an example in the upcoming slides
  • 23. Slide 23 http://www.edureka.co/php-mysql HTML Form  See the below example for HTML form with two text boxes and one submit button <html> <body> <form action=“save.php" method="post"> First Name: <input type="text" name=“firstname"><br> Last Name: <input type="text" name=“lastname"><br> <input type="submit"> </form> </body> </html>  The user enters the above information and clicks the submit button, the information is sent to a file called “save.php”
  • 24. Slide 24 http://www.edureka.co/php-mysql Processing Forms  The form data is sent to a PHP file for processing  We can send form data to server using two methods • GET method • POST method  In the previous code, we used POST method to send data. See the below example, to display the submitted data. To print the values, use the below code in save.php <?php Your First name is: <?php echo $_POST["firstname"]; ?> <br> Your Lastname is: <?php echo $_POST["lastname"]; ?> ?>
  • 25. Slide 25 http://www.edureka.co/php-mysql Get Method  GET method passes argument from one page to the next page.  It appends the indicated variable name(s) and values(s) to the URL. The value and the page name separated by question-mark(?) <form action=“display.php” method=“get”> Name: <input type=“text” name=“name”><br/> Email:<input type=“text” name=“email”><br/> <input type=“submit” value=“submit”> </form> <?php echo “Name: ”.$_GET*‘name’+; echo “Email: ”.$_GET*‘email’+; ?>
  • 26. Slide 26 http://www.edureka.co/php-mysql Get Method (Continued)  Advantage: • It constructs an actual new and differentiable URL query string. Users can now bookmark this page  Disadvantage: • The GET method is not suitable for logins because the username and password are fully visible onscreen as well as potentially stored in the client browser’s memory as a visited page • Every GET submission is recorded in the web server log, data set included • Because the GET method assigns data to a server environment variable, the length of the URL is limited
  • 27. Slide 27 http://www.edureka.co/php-mysql Post Method  POST is the preferred method of form submission  The form data is included in the body of the form when it is forwarding to the processing agent. There will be no change in the URL <form action=“display.php” method=“post”> Name: <input type=“text” name=“name”><br/> Email:<input type=“text” name=“email”><br/> <input type=“submit” value=“submit”> </form>  POST Method data can be accessed using $_POST variable <?php echo “Name: ”.$_POST*‘name’+; echo “Email: ”.$_POST*‘email’+; ?>
  • 28. Slide 28 http://www.edureka.co/php-mysql Post Method (Continued)  Advantages: • It is more secure than GET because user-entered information is never visible in the URL • It is much larger limit on the amount of data than can be passed  Disadvantages: • The results at a given moment cannot be bookmarked • This methods can be incompatible with certain firewall setups, which strip the form data as a security measure
  • 29. Slide 29 http://www.edureka.co/php-mysql PHP Functions  A function is a set of codes which are used to perform some specific tasks  Its main advantage is reusability. Instead of defining a code repeatedly, we can create functions and use them when needed  The function will not execute directly when the program loads. We need to call a function  There are two types of function available in PHP • Built-in functions - The real power of PHP is its functions. PHP has more than 1000 built-in functions. They can be invoked directly • User defined functions - We can also create our own functions. We will discuss about the creation of our own functions in next slide
  • 30. Slide 30 http://www.edureka.co/php-mysql PHP Functions Syntax Example: function functionName() { set of code to be executed; }  Syntax to call a function: functionName();  Rules to follow while naming a function: • Function names are NOT case-sensitive • Function name starts with a letter or underscore • Function name cannot start with numbers
  • 31. Slide 31 http://www.edureka.co/php-mysql PHP Functions Return Value  Function can return a value. It will return one value or more than one value using array  It returns the value using the return keyword. If the return statement is found in the function it will stop execution and send the value to the callback function.
  • 32. Slide 32 http://www.edureka.co/php-mysql Function Parameters  Function parameters are variables passes to the function inside the parentheses. They are declared much like a typical variable would be: <?php // multiply a value by 10 and return it to the caller function multiply ($value) { $value = $value * 10; return $value; } $retval= multiply (10); Print "Return value is $retvaln"; ?>
  • 33. Slide 33 http://www.edureka.co/php-mysql Object Oriented Concepts  Object Oriented Programming (OOP) is a programming concept used to design our application • Applications can be of any type • Web based application • Window based application • It is used to write programming in object model structure  Advantages of Object Oriented Programming • Re-Usability of your code • Easy to Maintain • Good Level of Abstraction
  • 34. Slide 34 http://www.edureka.co/php-mysql Classes  Defining PHP Classes • Class is a user defined data type which includes functions and member variables • It is used to define object. It is the blueprint of the object  Class Declaration • Class is declared using class keyword followed by the name • A set of braces used to declare variables and functions • Variables can be declared using var keyword followed by $ <?php class classname { var$var1; var$var2 = "constant text"; function myfunc($arg1, $arg2) { //function code } } ?>
  • 35. Slide 35 http://www.edureka.co/php-mysql Creating Objects in PHP  In Object Oriented language, properties are called member variables. And, behaviors are called member functions • Once we defined our class, then we can create as many objects using the new operator • Pen is class, Hero pen, Reynolds etc are called its objects  Syntax $objectname= new classname(); Example: $hero = new Pen; $reynolds= new Pen;
  • 36. Slide 36 http://www.edureka.co/php-mysql Calling Member Functions  After creating objects, we can access our member functions  We can only access the member function of the class of which we created objects  Let us see how to access member functions using the objects $hero, $reynolds Example Assigning values to the object $hero by accessing its member functions $hero -> setPrice("100"); //assigns value 100 to price variable $hero -> setColor("Green"); //assigns value green to color variable $hero -> setType("Ink Pen"); //assigns value Ink Pen to type variable $hero -> setWritingcolor(“blue”); //assigns value blue to writing color of the pen
  • 37. Slide 37 http://www.edureka.co/php-mysql Constructor Functions  Constructor is a special type of function  It is automatically invoked when an object is created. So we can use this function for initialization  To define a constructor, PHP provides a special function called __construct(). We can pass any number of arguments to this function  A function can also become a constructor, if it defined by the same name of the class  Two ways to declare constructors • __construct() function • Define function using same class name
  • 38. Slide 38 http://www.edureka.co/php-mysql Constructor Functions (Continued) Method 1: class classname { function __construct(p1, p2, ..., pN]){ /* Class initialization code */ } } Method 2: class classname { function classname(p1, p2, ..., pN]){ /* Class initialization code */ } }
  • 39. Slide 39 http://www.edureka.co/php-mysql Inheritance  Inheritance is the method of inheriting one class properties to other class  We can achieve this by using ‘extends’ keyword Class parentclass { //parent class definition } Class childclass extends parentclass { //child class definition }
  • 40. Slide 40 http://www.edureka.co/php-mysql Function Overriding  Function overriding is nothing but overriding the function of parent class to child class and modify those functions  Using overriding, we can alter function definition in child class  To override, we need to create same function in sub class which it is in base class
  • 41. Slide 41 http://www.edureka.co/php-mysql class baseclass { public function one() { echo “First function”; } public function two() { echo “second function”; } } class childclass extends baseclass { function two($text) //overriding function2 { echo "$text "; } } $text = new childclass(); $text->two("Sachin");//it will print Sachin Function Overriding  Example:
  • 42. Slide 42 http://www.edureka.co/php-mysql Access Modifiers  Access modifiers is nothing but the level of access and the visibility of the member variables and member functions  We can use this access modifiers to show or hide data  We have three access modifiers in PHP • Private • Protected • Public
  • 43. Slide 43 http://www.edureka.co/php-mysql Final Keyword  Final is a keyword  If we define the class as final then we cannot extend the class  If we declare the method as final we cannot override the method  Syntax for Defining Function as Final final public function functioname() { //function definition comes here }  Syntax for Defining Class as Final final class classname { //class definition comes here }
  • 44. Slide 44 http://www.edureka.co/php-mysql Database  A database is a unique application that organizes a group of data  Each database application has one or more APIs for creating, managing, accessing, searching and duplicating the data it holds  Hence, the data can easily be accessed, managed, and updated
  • 45. Slide 45 http://www.edureka.co/php-mysql MySQL Introduction  MySQL is a database system which is used on the web and runs on the server  It uses standard SQL  It is very fast, reliable and easy to use and also it is ideal for both small and large applications
  • 46. Slide 46 http://www.edureka.co/php-mysql MySQL Connection  Using PHP Script • Using mysql_connect() function we can open a database connection • This function requires five parameters and all are optional  Syntax mysql_connect(server,user,pass,new_link,client_flag);
  • 47. Slide 47 http://www.edureka.co/php-mysql MySQL Disconnect  Using PHP Script • Using mysql_close() function we can disconnect from MySQL server • This function takes single parameter  Syntax mysql_close(resource $link_identifier);  If we did not specify any parameter then the last opened database is closed
  • 48. Slide 48 http://www.edureka.co/php-mysql Execute MySQL Queries  Using PHP function mysql_query() we can run a MySQL query.  This function needs two parameters and returns Boolean value  Function Syntax mysql_query(sql_query, connection);  First parameter is mandatory. sql_query parameter is mandatory. It specifies the original query to be executed  The second parameter is optional. It is the connection parameter. If we did not specified, it takes the last opened connection  Consider we are going to create a database ‘student_details’ to store student information
  • 49. Slide 49 http://www.edureka.co/php-mysql Fetching Data  Select Query • Data Manipulation –Select Query • Select statement is used to fetch data from the database • Fetching data can be simple queries or complex queries  To select data using PHP script, we can use mysql_query() function • Write the select query inside the mysql_query() function • This function is used to execute MySQL queries • To fetch the selected data using select query we can use two functions mysql_fetch_array() mysql_fetch_assoc()
  • 50. Questions Slide 50 http://www.edureka.co/php-mysqlTwitter @edurekaIN, Facebook /edurekaIN, use #AskEdureka for Questions
  • 51. Slide 51 http://www.edureka.co/php-mysql Course Topics  Module 1 » PHP Basics and Conditional Logic  Module 2 » Functions and Error Handling  Module 3 » Object Oriented Programming  Module 4 » MySQL Installation and Basics  Module 5 » Advance Queries and Data Manipulation using PHP Module 6 » MVC Infrastructure Basics & Introduction to CakePHP Module 7 » CakePHP Controller, Views and Layout  Module 8 » Models and Database Interaction in CakePHP  Module 9 » Creating Dynamic Forms using CakePHP Html Helpers  Module 10 » Using MVC & CakePHP to develop a website
  • 52. Slide 52 LIVE Online Class Class Recording in LMS 24/7 Post Class Support Module Wise Quiz Project Work Verifiable Certificate http://www.edureka.co/php-mysql How it Works?