Skip to content

Instantly share code, notes, and snippets.

@rmasters
Created October 31, 2010 00:28
Show Gist options
  • Save rmasters/655925 to your computer and use it in GitHub Desktop.
Save rmasters/655925 to your computer and use it in GitHub Desktop.
<?php
$conn = new MySQLi("localhost", "root", "password", "widget_corp");
if ($conn->connect_errno()) {
die("Failed to connect: " . $conn->connect_error());
}
$result = $conn->query("SELECT * FROM subjects");
// You wouldn't usually have this, as you only get an error if the sql's
// wrong
if (!$result) {
die("Query error: #" . $conn->errno() . ": " . $conn->error());
}
// Collect data from query
$resultSet = array();
while ($row = $result->fetch_assoc()) {
$resultSet[] = $row;
}
$result->free();
$conn->free();
?>
<html>
<body>
<?php foreach($resultSet as $row): ?>
<p><strong><?= $row["col1"] ?></strong>: <?= $row["col2"] ?></p>
<?php endforeach; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment