<html>
<head>
<title>Test PHP Database Connection to Mysql</title>
</head>
<body>
<h1>Test PHP Database Connection to Mysql</h1>

<?php

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    $host = 'localhost';
    $db   = 'demo';
    $user = 'demo';
    $pswd = 'demo';    

    $output=null;
    $retval=null;
    exec('whoami', $output, $retval);

    print("<br><b>Attempting to connect to Oracle server on: $host and $db ...</b><br>\n");
    print("<b>Running under userid... </b>" . $output[0] . "<br><br>\n");

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

    $connect = mysqli_connect($host,$user,$pswd);
    if (! $connect) {
        die('Could not connect: ' . mysqli_connect_error());
    }
    print("<b>Connected to DB server on: $host</b><br>");

    // Select a database ----------------------------------------------------

    $selectDB = mysqli_select_db( $connect, $db);
    if (! $selectDB) {
        die ('Could not select a database:' . mysqli_error($connect));
    }
    print("<b>Database selected: $db</b><br><br>");

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

    $sql    = 'select fname, lname, ssn from student';
    $result = mysqli_query($connect, $sql);
    if (! $result) {
        die('Could not execute query: ' . mysqli_error($connect));
    }
    while ($row = mysqli_fetch_assoc($result)) {
        echo $row['fname'],' ',$row['lname'],' ',$row['ssn'],'<br>';
    }

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

    mysqli_free_result($result);

    mysqli_close($connect);
?>

</body>
</html>