dfdfd
 multiline
 $txt = "Hello world!"; $x = 5; $y = 10.5; echo $txt; Echo $Txt; * Variable name must begin with a letter or a underscore( must not use numeric)
 n is replaced by the newline character  t is replaced by the tab character  $ is replaced by the dollar sign itself ($)  " is replaced by a single double-quote (")  is replaced by a single backslash ()
 අගය නනොනෙනස්ෙ පෙතී.  <?php  define("MINSIZE", 50);  echo MINSIZE;  echo constant("MINSIZE"); // same thing as the previous line  ?>
<?php $cars = array("Volvo", "BMW", "Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>
Syntax if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
Example <?php $t = 1000; if ($t < 500) { echo “Small one"; } else { echo “Big one"; } ?>
 while (condition is true) { code to be executed; }  <?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?>
 <?php $x = 0; while($x < 10) { if ($x == 4) { break; } echo "The number is: $x <br>"; $x++; } ?>
 Login using your root (user)  From the main menu choose Databases  In the create database field type in a name for your database
 Click on Users in the main menu.  Choose the Add User option.  In the section Login Information - type in a username, localhost and a password
 GLOBAL privileges apply to ALL databases on the server ( leave this section BLANK)  Then click the Add User button  Click Edit Privileges to assign access to a specific database of created user
 <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>
 $conn->close();
 $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; }
$sql = "DELETE FROM MyGuests WHERE id=3"; if ($conn->query($sql) === TRUE) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . $conn->error; }
 $sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn- >error; }

Php

  • 1.
  • 4.
  • 5.
     $txt ="Hello world!"; $x = 5; $y = 10.5; echo $txt; Echo $Txt; * Variable name must begin with a letter or a underscore( must not use numeric)
  • 6.
     n isreplaced by the newline character  t is replaced by the tab character  $ is replaced by the dollar sign itself ($)  " is replaced by a single double-quote (")  is replaced by a single backslash ()
  • 8.
     අගය නනොනෙනස්ෙපෙතී.  <?php  define("MINSIZE", 50);  echo MINSIZE;  echo constant("MINSIZE"); // same thing as the previous line  ?>
  • 9.
    <?php $cars = array("Volvo","BMW", "Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>
  • 10.
    Syntax if (condition) { codeto be executed if condition is true; } else { code to be executed if condition is false; }
  • 11.
    Example <?php $t = 1000; if($t < 500) { echo “Small one"; } else { echo “Big one"; } ?>
  • 12.
     while (conditionis true) { code to be executed; }  <?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?>
  • 13.
     <?php $x =0; while($x < 10) { if ($x == 4) { break; } echo "The number is: $x <br>"; $x++; } ?>
  • 14.
     Login usingyour root (user)  From the main menu choose Databases  In the create database field type in a name for your database
  • 15.
     Click onUsers in the main menu.  Choose the Add User option.  In the section Login Information - type in a username, localhost and a password
  • 16.
     GLOBAL privilegesapply to ALL databases on the server ( leave this section BLANK)  Then click the Add User button  Click Edit Privileges to assign access to a specific database of created user
  • 17.
     <?php $servername ="localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>
  • 18.
  • 19.
     $sql ="INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; }
  • 20.
    $sql = "DELETEFROM MyGuests WHERE id=3"; if ($conn->query($sql) === TRUE) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . $conn->error; }
  • 21.
     $sql ="UPDATE MyGuests SET lastname='Doe' WHERE id=2"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn- >error; }