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
PPT
Class 5 - PHP Strings
PPT
PHP variables
PPTX
Class 8 - Database Programming
PDF
Swift 함수 커링 사용하기
PDF
Introduction to Clean Code
PDF
Sorting arrays in PHP
PPTX
PHP Functions & Arrays
Php variables
Class 5 - PHP Strings
PHP variables
Class 8 - Database Programming
Swift 함수 커링 사용하기
Introduction to Clean Code
Sorting arrays in PHP
PHP Functions & Arrays

What's hot (20)

PDF
Web 4 | Core JavaScript
DOCX
PERL for QA - Important Commands and applications
PPT
Php Chapter 1 Training
PDF
Web 8 | Introduction to PHP
PDF
Web 9 | OOP in PHP
PPT
Class 2 - Introduction to PHP
PPTX
Introduction in php
PPTX
PHP Strings and Patterns
PPTX
Introduction in php part 2
PDF
Web 10 | PHP with MySQL
PPTX
Js types
PPTX
String variable in php
PDF
How to write code you won't hate tomorrow
PDF
Some OOP paradigms & SOLID
PDF
Functions in PHP
PDF
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
PPT
Class 4 - PHP Arrays
PDF
Swift에서 꼬리재귀 사용기 (Tail Recursion)
PDF
Javascript essentials
Web 4 | Core JavaScript
PERL for QA - Important Commands and applications
Php Chapter 1 Training
Web 8 | Introduction to PHP
Web 9 | OOP in PHP
Class 2 - Introduction to PHP
Introduction in php
PHP Strings and Patterns
Introduction in php part 2
Web 10 | PHP with MySQL
Js types
String variable in php
How to write code you won't hate tomorrow
Some OOP paradigms & SOLID
Functions in PHP
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
Class 4 - PHP Arrays
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Javascript essentials
Ad

Viewers also liked (9)

PPT
Linux seminar
PPT
Open source technology
PPTX
PHP Summer Training Presentation
PPT
Php Ppt
PPTX
Lamp technology
PPTX
OPEN SOURCE SEMINAR PRESENTATION
PPT
Php Presentation
PPT
Open Source Technology
PPT
Introduction to PHP
Linux seminar
Open source technology
PHP Summer Training Presentation
Php Ppt
Lamp technology
OPEN SOURCE SEMINAR PRESENTATION
Php Presentation
Open Source Technology
Introduction to PHP
Ad

Similar to Php & my sql (20)

PPTX
Php functions
PDF
PHP Conference Asia 2016
PPTX
PHP PPT FILE
PDF
php AND MYSQL _ppt.pdf
PDF
Php Tutorials for Beginners
PPT
PHP and MySQL
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PPT
Web Technology_10.ppt
PPT
Introduction to Perl
PPSX
Javascript variables and datatypes
PPSX
What's New In C# 7
KEY
ddd+scala
KEY
Can't Miss Features of PHP 5.3 and 5.4
KEY
Good Evils In Perl (Yapc Asia)
PDF
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
PPTX
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PPT
Php Chapter 2 3 Training
PDF
Mocking Demystified
PDF
Symfony2 - extending the console component
PDF
Php functions
PHP Conference Asia 2016
PHP PPT FILE
php AND MYSQL _ppt.pdf
Php Tutorials for Beginners
PHP and MySQL
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
Web Technology_10.ppt
Introduction to Perl
Javascript variables and datatypes
What's New In C# 7
ddd+scala
Can't Miss Features of PHP 5.3 and 5.4
Good Evils In Perl (Yapc Asia)
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
Php Chapter 2 3 Training
Mocking Demystified
Symfony2 - extending the console component

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Empathic Computing: Creating Shared Understanding
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The AUB Centre for AI in Media Proposal.docx
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Monthly Chronicles - July 2025
Empathic Computing: Creating Shared Understanding
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

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");