SlideShare a Scribd company logo
1 of 31
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

What's hot

PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsSunil Kumar Gunasekaran
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 TrainingChris Chubb
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 
PHP Strings and Patterns
PHP Strings and PatternsPHP Strings and Patterns
PHP Strings and PatternsHenry Osborne
 
String variable in php
String variable in phpString variable in php
String variable in phpchantholnet
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
Some OOP paradigms & SOLID
Some OOP paradigms & SOLIDSome OOP paradigms & SOLID
Some OOP paradigms & SOLIDJulio Martinez
 
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object Calisthenics1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object CalisthenicsLucas Arruda
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP ArraysAhmed Swilam
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)진성 오
 

What's hot (20)

Web 4 | Core JavaScript
Web 4 | Core JavaScriptWeb 4 | Core JavaScript
Web 4 | Core JavaScript
 
PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applications
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 Training
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Web 9 | OOP in PHP
Web 9 | OOP in PHPWeb 9 | OOP in PHP
Web 9 | OOP in PHP
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
PHP Strings and Patterns
PHP Strings and PatternsPHP Strings and Patterns
PHP Strings and Patterns
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Web 10 | PHP with MySQL
Web 10 | PHP with MySQLWeb 10 | PHP with MySQL
Web 10 | PHP with MySQL
 
Js types
Js typesJs types
Js types
 
String variable in php
String variable in phpString variable in php
String variable in php
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Some OOP paradigms & SOLID
Some OOP paradigms & SOLIDSome OOP paradigms & SOLID
Some OOP paradigms & SOLID
 
Intoduction to php strings
Intoduction to php  stringsIntoduction to php  strings
Intoduction to php strings
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object Calisthenics1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 

Viewers also liked

Viewers also liked (9)

Linux seminar
Linux seminarLinux seminar
Linux seminar
 
Open source technology
Open source technologyOpen source technology
Open source technology
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Lamp technology
Lamp technologyLamp technology
Lamp technology
 
OPEN SOURCE SEMINAR PRESENTATION
OPEN SOURCE SEMINAR PRESENTATIONOPEN SOURCE SEMINAR PRESENTATION
OPEN SOURCE SEMINAR PRESENTATION
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Open Source Technology
Open Source TechnologyOpen Source Technology
Open Source Technology
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similar to Php & my sql

PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016Britta Alex
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfAlexShon3
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 TrainingChris Chubb
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console componentHugo Hamon
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangSean Cribbs
 

Similar to Php & my sql (20)

Php functions
Php functionsPhp functions
Php functions
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Slide
SlideSlide
Slide
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 

Recently uploaded

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Recently uploaded (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

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