CPSC415A
Web Programming

Day 19 Notes

PHP & SQL

Create Connection

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
        . $mysqli->connect_error);
}
echo 'Success... ' . $mysqli->host_info . "\n";
$mysqli->close();

Make Query

$query_string = "SELECT * FROM Table";
if ($result = $mysqli->query($query_string)) {
    echo "Select returned " . result->num_rows . " rows.\n");
    while ($row = $result->fetch_assoc()) {
        echo $row["column"] . "\n";
    }
    $result->close();
}