Created
October 31, 2010 00:28
-
-
Save rmasters/655925 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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