| HTTP Requests
                        
                                                                                    
                                                                                            |  | Access URL parameters. |  
                                                                                            |  | Access POST request body content. |  
                                                                                            |  | Current php document url. |  Built-in Functions
                        
                                                                                    
                                                                                            |  | Includes the PHP file "x.php". |  
                                                                                            |  | Renders  <content>
  on the page on load |  
                                                                                            |  | Exits the script, with a message. |  
                                                                                            |  | Returns  true
  if  $a
  is not  NULL
 |  
                                                                                            |  | Returns  true
  if  $a
  and  $b
  is not  NULL
 |  
                                                                                            |  | Prints readable information of  $x
 |  
                                                                                            |  | Checks if  $x
  is empty or  false
 |  
                                                                                            |  | Removes leading and trailing whitespaces from  $x
 |  PHP MS SQL DLL Functions
                        
                                                                                    
                                                                                            |  | Connect to Microsoft SQL Server db. |  
                                                                                            |  | Prepares and executes a query. |  
                                                                                            |  | Frees resources for the statement. |  
                                                                                            |  | Closes the SQL connection. |  
                                                                                            |  | Returns a row as an array. |  
                                                                                            |  | Move to the next result of the statement. |  
                                                                                            |  | Returns error and warning information. |  Example Form Loading
                        
                                    
                        | <?php
    // Get the parameter: "Fruit" from the URL query string.
    // Eg. https://example.php/?Fruit=Apple
    $Fruit = $GET['Fruit'];
?>
// Render the variable $Fruit in the HTML
<div>
    <?php echo $Fruit; ?>
</div>
 |  Example SQL Query Insert
                        
                                    
                        | <?php
    $Name = "John Doe";
    $Age = 25;
    $db_server = "<server_hostname>"; 
    $db_username = "<database_username>";
    $db_password = "<database_password>";
    $db_database = "<database_name>";
    $connectionInfo = array("Database"=>$db_database, "UID"=>$db_username, "PWD"=>$db_password);
    $conn = sqlsrv_connect($db_server, $connectionInfo);
    $tsql = "INSERT INTO dbo.Customers ( Name, Age ) VALUES";
    // Append more string literals to the variable $tsql to form the full query
    $tsql .= "('".$Name."', '".$Age."')";
    $stmt = sqlsrv_query($conn, $tsql);
    // Free statement and connection resources.
    sqlsrv_free_stmt($stmt);
    sqlsrv_close($conn);
?>
 |  |  | Basic Syntax
                        
                                                                                    
                                                                                            |  | Creates a variable, can be of any type. |  
                                                                                            |  | A literal string |  
                                                                                            |  | Comments will not execute. |  
                                                                                            |  | Concatenates  "x"
  and  "y"
 , resulting in  "xy"
 |  Flow Control
                        
                                                                                    
                                                                                            | if (x) {y} else if (a) {b} else {z}
 | Conditional code block, if  x
  is  true
 , run  y
 . Otherwise, if  a
  is  true
 , run  b
 . Otherwise, run  z
 |  
                                                                                            |  | A  do ... while
  loop. Executes  x
  as long as  y
  is  true
 |  
                                                                                            |  | A  while
  loop. Executes  y
  as long as  x
  is  true
 |  Comparison Operators
                        
                                                                                    
                                                                                            |  | Returns  true
  if  $x
  is  false
 |  
                                                                                            |  | Returns  true
  if  $x
  matches  $y
  in value |  
                                                                                            |  | Returns  true
  if  $x
  matches  $y
  in value and type |  
                                                                                            |  | Returns  true
  if  $x
  does not match  $y
  in value |  
                                                                                            |  | Returns  true
  if  $x
  does not match  $y
  in value or type |  
                                                                                            |  |  |  
                                                                                            |  | Returns  true
  if both  $x
  and  $y
  is  true
 |  
                                                                                            |  | Returns  true
  if either  $x
  or  $y
  is  true
 |  
                                                                                            |  | Returns  true
  if  $x
  is greater than  $y
 |  
                                                                                            |  | Returns  true
  if  $x
  is less than  $y
 |  
                                                                                            |  | Returns  true
  if  $x
  is greater than or equal to  $y
 |  
                                                                                            |  | Returns  true
  if  $x
  is less than or equal to  $y
 |  Example Form Submission
                        
                                    
                        | <?php
    // Check if the request is a HTTP POST request. If it is, $_POST will not be empty.
    if ($_POST) {
        $Fruit = $_POST['Fruit'];
        // Fruit will have the value from the input element with the property: name="fruit" upon submission.
    }
?>
<form method="post" action="<?=$_SERVER['php_self']?>">
    <input type="text" name="fruit" id="fruit_id" />
    <input type="submit" value="Submit" />
</form>
 |  Example SQL Query Select
                        
                                    
                        | <?php
    $db_server = "<server_hostname>";
    $db_username = "<database_username>";
    $db_password = "<database_password>";
    $db_database = "<database_name>";
    $connectionInfo = array("Database"=>$db_database, "UID"=>$db_username, "PWD"=>$db_password);
    $conn = sqlsrv_connect($db_server, $connectionInfo);
    $tsql = "SELECT FirstName, LastName FROM dbo.Customers";
    $stmt = sqlsrv_query($conn, $tsql);
    if( $stmt === false) {
        die( print_r( sqlsrv_errors(), true) );
    }
    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
          echo $row['LastName'].", ".$row['FirstName']."<br />";
    }
    // Free statement and connection resources.
    sqlsrv_free_stmt($stmt);
    sqlsrv_close($conn);
?>
 |  | 
            
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets