Languages and Software to Be Covered (Cont.)


PHP (HyperText Preprocessor)
PHP is a general-purpose server-side scripting language which can be embedded into HTML to create a wide variety of mini-applications, but can also be used to build large-scale complex applications.

<html>
 <body>
  <?php
   echo  "Pick: ";
   $cars = $_POST[cars];
   foreach ( $cars as $car )
    echo  "$car ";
  ?>
 </body>
</html>





PHP and MySQL
MySQL statements can be embedded in PHP programs.

<html><body>
 <?php
  $username = "your_id";
  $database = "your_db";
  $password = "your-pw";
  $host     = "undcemmysql.mysql.database.azure.com";

  // Initializing MySQLi
  $conn     = mysqli_init( );

  // Creating an SSL connection
  mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );

  // Opening a new connection to the MySQL server
  mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );

  // Connect to the database.
  if ( $conn->connect_errno )
    die( 'Failed to connect to MySQL: ' . $conn->connect_error );

  // Compose the query.
  $query = "SELECT s.name FROM student1 s WHERE ";
  $token = strtok( $_POST['name'], " " );
  if ( $token == false )
    $query .= "s.name LIKE '%%'";
  else
    while ( $token !== false ) {
      $query .= "(UPPER(s.name) " . "LIKE '%" . strtoupper($token) . "%') ";
      $token  = strtok( " " );
      if ( $token !== false )  $query .= " OR ";
    }
  echo( $query );

  // Execute the query.
  $result = $conn->query( $query );

  // Print the results row by row.
  $i = 0;
  if ( $result->num_rows > 0 )
    while ( $row = $result->fetch_assoc( ) )
      echo( ++$i . " đź ž " . $row['name'] );

  // Close the database connection.
  $conn->close( );

 ?>
</body></html>
    Students’ names:   (listing all if empty)

         




      Secretary: “Doctor the invisible man has come.”    
      Secretary: “He says he has an appointment.”    
      Doctor: “Tell him I can’t see him.”