SlideShare a Scribd company logo
Php & mySQL
Operational Trail
Why PHP
 Open Source
 Very good support
 C/Java like language
 Cross Platform (Windows, Linux, Unix)
 Powerful, robust and scalable
PHP Elements
 Variables: placeholders for unknown or changing
    values
   Arrays: a variable to hold multiple values
   Conditional Statements: decision making
   Loops: perform repetitive task
   Functions: perform preset task or sub task
PHP statements
<?php
your statement is here;
don„t forget to end each statement with semicolon
  (“;”);
anything within this scope must be recognized by
  php or you‟ll get error;
?>
Naming variables
 Start with dollar sign ($)
 First character after $ cannot be number
 No spaces or punctuation
 Variable names are case-sensitive
 You‟re free to choose your own but …
 … meaningful naming is much better.
Assigning values to variables
 $myVar = $value;
 $myVar = 3.4; # assign a number
 $myVar = “I‟m cute”; // Assign a string
 $myVar = $yourVar; /* assign a variable */
 $myVar = “$name is a terrible creature”;
PHP Output & comments
 echo:
   echo “you‟re a creature”; // print you‟re a creature
   echo $name; /* print value of variable $name */
   echo(“my creatures”); # print my creatures
 print:
   print “you‟re a creature”;
   print $name;
   print(“my creatures”);
 Also printf and sprintf
Joining together
 Joining string
   $var = “Digital”.”Multimeter”;
 Joining variables
   $var = $var1.$var2.$var3……. ;
   $var = “$var1 $var2 $var3 …… “;
 Joining string and variable
   $var = $var1.”Zener diode”;
   $var .= “blogger”;
Calculation

 Operation         Operator   Example
 Addition             +           $x + $y
 Subtraction          -            $x - $y
 Multiplication       *            $x * $y
 Division             /            $x / $y
 Modulo Division      %           $x % $y
 Increment           ++         ++$x @ $x++
 Decrement            --         --$x @ $x--
Array
 Declaration
   $RGBcolor = array(“red”, “Blue”, “Green);
   $mycar[] = “Rapide”;
 Access
   $myarray[element number]
 Functions
   array_pop(); array_push(); array_rand();
   array_reverse; count(array); sort(array);
   print_r(array)
Making decision (if, if else, elseif)
if(condition is true) {
   //code will be executed here
}
if(condition is true) {
 //code will be executed here
}
else {
//code will be executed if condition is false
}
if(condition 1) { }
elseif (condition 2) { }
else { }
Comparison operator
 Symbol       Name
 ==           Equality
 !=           Inequality
 <>           Inequality
 ===          Identical
 !==          Not identical
 >            Greater than
 >=           Greater/equal than
 <            Less than
 <=           Less or equal than
Logical Operators
  Symbol      Name                         Use
   &&      Logical AND    True if both operands are true
   and     Logical AND    Same as &&
    ||      Logical OR    True if not both operands are
                          false
    or      Logical OR    Same as ||
   xor     Exclusive OR   True if one of operands is true
    !         NOT         Test for false
Switch statement
switch(variable being tested) {
case value1:
  statement;
  break;
case value2:
  statement;
  break;
  .
  .
  .
  .
default:
  statment
}
Conditional (ternary) operator
 condition ? value if true : value if false;
$age = 17;
$fareType = $age > 16 ? 'adult' : 'child';
Loop
 while(condition is true) { statement; }
 do { statement; } while (condition is true);
 for(initial value; test; increase/decrease)
  {statement;}
 foreach(array_name as temporary variable) {
  statement;}
Breaking loop
 break: exit loop;
 continue: exit current loop but continue next
 counter
PHP Function
 A block of code that performs specific task
   represented by a name and can be called
   repeatedly.
function function_name()
{
//code is here
return var; // may return value
}
Date & Time
 time(): timestamp from 1st January 1970
 date(format, timestamp):
   Format:-
     d: day of the month (1-31)
     m: month (1-12)
     Y: year in 4 digits
   Timestamp (optional)
     Default is current date and time
   Date Add / Date Diff
     Under DateTime class: DateTime:add, DateTime:diff
String function
 strlen(str): string length
 strpos(str, str_find, start): find string occurance
 strrev(str): string reverse
 substr(str, start_str, length): return part of string
 substr_replace(str, replacement, start, length):
  replace part of string
Math Function
 Absolute value: abs(0 – 300)
 Exponential: pow(2, 8)
 Square root: sqrt(100)
 Modulo: fmod(20, 7)
 Random: rand()
 Random mix & max: rand(1, 10)
 Trigonometry: sin(), cos(), tan()
Building Form & input
 <form action=“” method=“URL” enctype=“data">
    </form>
   method: get or post
   action: URL to be accessed when form is submitted
   enctype: type of data to be submit to the server
   All inputs must be within the form
   Textfield = <input type=“text” name=“”>
   Checkbox = <input type=“checkbox” name=“”>
   Radio Button = <input type=“radio” name=“”>
   Textarea = <textarea name=“”></textarea>
   List = <select name=“”><option
    value=“”></option></select>
Getting information from form
 print_r($_POST): form data retrieval in array
 $_POST: contains value sent through post
  method
 $_GET: contains value sent through get method
MySQL function (connection)
 Connection to database
 mysql_connect(servername, username,
   password)
<?php
$test = mysql_connect(“localhost”, “admin”, “pass”);
if($test)
   echo “success”;
else
   die(“cannot connect maa…”);
?>
 Close connection using
   mysql_close(connection_name)
MySQL (query)
 Select database: mysql_select_db(“database”,
  connection);
 Run query: mysql_query(“SQL query);
  <?php
  $test = mysql_connect(“localhost”, “root”,””);
  mysql_select_db(“data”, $test);
  mysql_query(“Select * from table”);
  ?>
 SQL query: SELECT fieldname FROM tablename
MySQL (Display query)
 mysql_fetch_array($result)
 $result is array of data
 Example:
  <?php
      $result = mysql_query(“MySQL select
  query”);
      while($row = mysql_fetch_array($result)) {
            echo $row[„fieldname‟];
      }
  ?>
MySQL insert data
 SQL command: INSERT INTO table_name
  (field1, field2, …) VALUES (value1, value2, …)
 Example:
  mysql_query("INSERT INTO Address (No, Road,
  Postcode) VALUES (11, „Jalan 19/2C', 40000)");
MySQL update data
 SQL command: UPDATE table_name SET
  field1=value1, field2=value2,... WHERE
  field=some_value
 Example:
  mysql_query(“UPDATE Address SET
  Postcode=40900 WHERE No=13");
MySQL delete data
 SQL command: DELETE FROM table_name
  WHERE some_column = some_value
 Example:
  mysql_query(“DELETE from Address WHERE
  Postcode=40900");
File input/output

More Related Content

PPT
Php variables
Ritwik Das
 
PPT
Class 5 - PHP Strings
Ahmed Swilam
 
PPT
PHP variables
Siddique Ibrahim
 
PPTX
Class 8 - Database Programming
Ahmed Swilam
 
PDF
Swift 함수 커링 사용하기
진성 오
 
PDF
Introduction to Clean Code
Julio Martinez
 
PDF
Sorting arrays in PHP
Vineet Kumar Saini
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
Php variables
Ritwik Das
 
Class 5 - PHP Strings
Ahmed Swilam
 
PHP variables
Siddique Ibrahim
 
Class 8 - Database Programming
Ahmed Swilam
 
Swift 함수 커링 사용하기
진성 오
 
Introduction to Clean Code
Julio Martinez
 
Sorting arrays in PHP
Vineet Kumar Saini
 
PHP Functions & Arrays
Henry Osborne
 

What's hot (20)

PDF
Web 4 | Core JavaScript
Mohammad Imam Hossain
 
DOCX
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
PPT
Php Chapter 1 Training
Chris Chubb
 
PDF
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
PDF
Web 9 | OOP in PHP
Mohammad Imam Hossain
 
PPT
Class 2 - Introduction to PHP
Ahmed Swilam
 
PPTX
Introduction in php
Bozhidar Boshnakov
 
PPTX
PHP Strings and Patterns
Henry Osborne
 
PPTX
Introduction in php part 2
Bozhidar Boshnakov
 
PDF
Web 10 | PHP with MySQL
Mohammad Imam Hossain
 
PPTX
Js types
LearningTech
 
PPTX
String variable in php
chantholnet
 
PDF
How to write code you won't hate tomorrow
Pete McFarlane
 
PDF
Some OOP paradigms & SOLID
Julio Martinez
 
PDF
Functions in PHP
Vineet Kumar Saini
 
PDF
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
Lucas Arruda
 
PPT
Class 4 - PHP Arrays
Ahmed Swilam
 
PDF
Swift에서 꼬리재귀 사용기 (Tail Recursion)
진성 오
 
PDF
Javascript essentials
Bedis ElAchèche
 
Web 4 | Core JavaScript
Mohammad Imam Hossain
 
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
Php Chapter 1 Training
Chris Chubb
 
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
Web 9 | OOP in PHP
Mohammad Imam Hossain
 
Class 2 - Introduction to PHP
Ahmed Swilam
 
Introduction in php
Bozhidar Boshnakov
 
PHP Strings and Patterns
Henry Osborne
 
Introduction in php part 2
Bozhidar Boshnakov
 
Web 10 | PHP with MySQL
Mohammad Imam Hossain
 
Js types
LearningTech
 
String variable in php
chantholnet
 
How to write code you won't hate tomorrow
Pete McFarlane
 
Some OOP paradigms & SOLID
Julio Martinez
 
Functions in PHP
Vineet Kumar Saini
 
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
Lucas Arruda
 
Class 4 - PHP Arrays
Ahmed Swilam
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
진성 오
 
Javascript essentials
Bedis ElAchèche
 
Ad

Viewers also liked (9)

PPT
Linux seminar
Buntha Chhay
 
PPT
Open source technology
aparnaz1
 
PPTX
PHP Summer Training Presentation
Nitesh Sharma
 
PPT
Php Ppt
vsnmurthy
 
PPTX
Lamp technology
Harish Sabbani
 
PPTX
OPEN SOURCE SEMINAR PRESENTATION
Ritwick Halder
 
PPT
Php Presentation
Manish Bothra
 
PPT
Open Source Technology
priyadharshini murugan
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
Linux seminar
Buntha Chhay
 
Open source technology
aparnaz1
 
PHP Summer Training Presentation
Nitesh Sharma
 
Php Ppt
vsnmurthy
 
Lamp technology
Harish Sabbani
 
OPEN SOURCE SEMINAR PRESENTATION
Ritwick Halder
 
Php Presentation
Manish Bothra
 
Open Source Technology
priyadharshini murugan
 
Introduction to PHP
Jussi Pohjolainen
 
Ad

Similar to Php & my sql (20)

PPTX
Php functions
JIGAR MAKHIJA
 
PDF
PHP Conference Asia 2016
Britta Alex
 
PPTX
PHP PPT FILE
AbhishekSharma2958
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PPT
PHP and MySQL
Sanketkumar Biswas
 
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
PPT
Web Technology_10.ppt
Aftabali702240
 
PPT
Introduction to Perl
NBACriteria2SICET
 
PPSX
Javascript variables and datatypes
Varun C M
 
PPSX
What's New In C# 7
Paulo Morgado
 
KEY
ddd+scala
潤一 加藤
 
KEY
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
KEY
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
PDF
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
PPTX
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
PPT
Php Chapter 2 3 Training
Chris Chubb
 
PDF
Mocking Demystified
Marcello Duarte
 
PDF
Symfony2 - extending the console component
Hugo Hamon
 
PDF
Slide
Naing Lin Aung
 
Php functions
JIGAR MAKHIJA
 
PHP Conference Asia 2016
Britta Alex
 
PHP PPT FILE
AbhishekSharma2958
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PHP and MySQL
Sanketkumar Biswas
 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
Web Technology_10.ppt
Aftabali702240
 
Introduction to Perl
NBACriteria2SICET
 
Javascript variables and datatypes
Varun C M
 
What's New In C# 7
Paulo Morgado
 
ddd+scala
潤一 加藤
 
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
Php Chapter 2 3 Training
Chris Chubb
 
Mocking Demystified
Marcello Duarte
 
Symfony2 - extending the console component
Hugo Hamon
 

Recently uploaded (20)

PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
Software Development Company | KodekX
KodekX
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Software Development Methodologies in 2025
KodekX
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 

Php & my sql

  • 3. Why PHP  Open Source  Very good support  C/Java like language  Cross Platform (Windows, Linux, Unix)  Powerful, robust and scalable
  • 4. PHP Elements  Variables: placeholders for unknown or changing values  Arrays: a variable to hold multiple values  Conditional Statements: decision making  Loops: perform repetitive task  Functions: perform preset task or sub task
  • 5. PHP statements <?php your statement is here; don„t forget to end each statement with semicolon (“;”); anything within this scope must be recognized by php or you‟ll get error; ?>
  • 6. Naming variables  Start with dollar sign ($)  First character after $ cannot be number  No spaces or punctuation  Variable names are case-sensitive  You‟re free to choose your own but …  … meaningful naming is much better.
  • 7. Assigning values to variables  $myVar = $value;  $myVar = 3.4; # assign a number  $myVar = “I‟m cute”; // Assign a string  $myVar = $yourVar; /* assign a variable */  $myVar = “$name is a terrible creature”;
  • 8. PHP Output & comments  echo:  echo “you‟re a creature”; // print you‟re a creature  echo $name; /* print value of variable $name */  echo(“my creatures”); # print my creatures  print:  print “you‟re a creature”;  print $name;  print(“my creatures”);  Also printf and sprintf
  • 9. Joining together  Joining string  $var = “Digital”.”Multimeter”;  Joining variables  $var = $var1.$var2.$var3……. ;  $var = “$var1 $var2 $var3 …… “;  Joining string and variable  $var = $var1.”Zener diode”;  $var .= “blogger”;
  • 10. Calculation Operation Operator Example Addition + $x + $y Subtraction - $x - $y Multiplication * $x * $y Division / $x / $y Modulo Division % $x % $y Increment ++ ++$x @ $x++ Decrement -- --$x @ $x--
  • 11. Array  Declaration  $RGBcolor = array(“red”, “Blue”, “Green);  $mycar[] = “Rapide”;  Access  $myarray[element number]  Functions  array_pop(); array_push(); array_rand(); array_reverse; count(array); sort(array); print_r(array)
  • 12. Making decision (if, if else, elseif) if(condition is true) { //code will be executed here } if(condition is true) { //code will be executed here } else { //code will be executed if condition is false } if(condition 1) { } elseif (condition 2) { } else { }
  • 13. Comparison operator Symbol Name == Equality != Inequality <> Inequality === Identical !== Not identical > Greater than >= Greater/equal than < Less than <= Less or equal than
  • 14. Logical Operators Symbol Name Use && Logical AND True if both operands are true and Logical AND Same as && || Logical OR True if not both operands are false or Logical OR Same as || xor Exclusive OR True if one of operands is true ! NOT Test for false
  • 15. Switch statement switch(variable being tested) { case value1: statement; break; case value2: statement; break; . . . . default: statment }
  • 16. Conditional (ternary) operator  condition ? value if true : value if false; $age = 17; $fareType = $age > 16 ? 'adult' : 'child';
  • 17. Loop  while(condition is true) { statement; }  do { statement; } while (condition is true);  for(initial value; test; increase/decrease) {statement;}  foreach(array_name as temporary variable) { statement;}
  • 18. Breaking loop  break: exit loop;  continue: exit current loop but continue next counter
  • 19. PHP Function  A block of code that performs specific task represented by a name and can be called repeatedly. function function_name() { //code is here return var; // may return value }
  • 20. Date & Time  time(): timestamp from 1st January 1970  date(format, timestamp):  Format:-  d: day of the month (1-31)  m: month (1-12)  Y: year in 4 digits  Timestamp (optional)  Default is current date and time  Date Add / Date Diff  Under DateTime class: DateTime:add, DateTime:diff
  • 21. String function  strlen(str): string length  strpos(str, str_find, start): find string occurance  strrev(str): string reverse  substr(str, start_str, length): return part of string  substr_replace(str, replacement, start, length): replace part of string
  • 22. Math Function  Absolute value: abs(0 – 300)  Exponential: pow(2, 8)  Square root: sqrt(100)  Modulo: fmod(20, 7)  Random: rand()  Random mix & max: rand(1, 10)  Trigonometry: sin(), cos(), tan()
  • 23. Building Form & input  <form action=“” method=“URL” enctype=“data"> </form>  method: get or post  action: URL to be accessed when form is submitted  enctype: type of data to be submit to the server  All inputs must be within the form  Textfield = <input type=“text” name=“”>  Checkbox = <input type=“checkbox” name=“”>  Radio Button = <input type=“radio” name=“”>  Textarea = <textarea name=“”></textarea>  List = <select name=“”><option value=“”></option></select>
  • 24. Getting information from form  print_r($_POST): form data retrieval in array  $_POST: contains value sent through post method  $_GET: contains value sent through get method
  • 25. MySQL function (connection)  Connection to database  mysql_connect(servername, username, password) <?php $test = mysql_connect(“localhost”, “admin”, “pass”); if($test) echo “success”; else die(“cannot connect maa…”); ?>  Close connection using mysql_close(connection_name)
  • 26. MySQL (query)  Select database: mysql_select_db(“database”, connection);  Run query: mysql_query(“SQL query); <?php $test = mysql_connect(“localhost”, “root”,””); mysql_select_db(“data”, $test); mysql_query(“Select * from table”); ?>  SQL query: SELECT fieldname FROM tablename
  • 27. MySQL (Display query)  mysql_fetch_array($result)  $result is array of data  Example: <?php $result = mysql_query(“MySQL select query”); while($row = mysql_fetch_array($result)) { echo $row[„fieldname‟]; } ?>
  • 28. MySQL insert data  SQL command: INSERT INTO table_name (field1, field2, …) VALUES (value1, value2, …)  Example: mysql_query("INSERT INTO Address (No, Road, Postcode) VALUES (11, „Jalan 19/2C', 40000)");
  • 29. MySQL update data  SQL command: UPDATE table_name SET field1=value1, field2=value2,... WHERE field=some_value  Example: mysql_query(“UPDATE Address SET Postcode=40900 WHERE No=13");
  • 30. MySQL delete data  SQL command: DELETE FROM table_name WHERE some_column = some_value  Example: mysql_query(“DELETE from Address WHERE Postcode=40900");