<?php
#=======================================================================
# Get data from a database
#=======================================================================
    $host = 'localhost';
    $db   = 'demo2';
    $user = 'demo2';
    $pswd = 'demo2';    

    // Connect to MySql database server -------------------------------------

    $connect = mysqli_connect($host,$user,$pswd,$db);
    if (! $connect) {
        die('Could not connect: ' . mysqli_connect_error());
    }

    // perform select query -------------------------------------------------

    $sql    = "SELECT order_id, firstname, lastname, address
               FROM cust_order
               ORDER BY order_id";
               
    $result = mysqli_query($connect, $sql);
    if (! $result) {
        die('Could not execute query: ' . mysqli_error($connect));
    } 

    // display the results -------------------------------------------------

    print( "ORDER# \t FNAME \t LNAME \t\t ADDRESS \n");         //print headers

    while ($row = mysqli_fetch_assoc($result))                  //loop thru every row in cursor
    {
        $order = $row['order_id'];
        $fname = $row['firstname'];
        $lname = $row['lastname'];
        $addr  = $row['address'];

        printf("%d \t %-7.7s %-15.15s %-16.16s \n", $order,$fname,$lname,$addr);
    }

    // release resources ----------------------------------------------------

    mysqli_free_result($result);
    mysqli_close($connect);
?>