Skip to content

Instantly share code, notes, and snippets.

@BaylorRae
Created February 22, 2012 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaylorRae/1886283 to your computer and use it in GitHub Desktop.
Save BaylorRae/1886283 to your computer and use it in GitHub Desktop.
<?php
// connect to the db
$mysql = new mysqli('localhost', 'root', 'root', 'users');
/*
* This is the "official" object oriented way to do it,
* BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
*/
if ($mysql->connect_error) {
die('Connect Error (' . $mysql->connect_errno . ') '
. $mysql->connect_error);
}
$people = $mysql->query("SELECT `id`, `name` FROM `people`");
if( $people == false ) {
die('Failed to get all people: ' . $mysql->error);
}
$mysql->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>People</title>
<meta charset="utf-8" />
<style>
html {
background: #f0f0f0;
margin: 0;
padding: 0;
}
body {
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-weight: 300;
width: 300px;
margin: 40px auto;
background: #fff;
padding: 20px;
}
h2 {
margin: 0;
padding: 0;
text-align: center;
}
</style>
</head>
<body>
<h2>The People</h2>
<ul>
<?php
while( $person = $people->fetch_object() ) {
echo '<li><strong>', $person->id, '</strong> - ', $person->name, '</li>';
}
?>
</ul>
</body>
</html>
Alias /phpMyAdmin "/Applications/MAMP/bin/phpMyAdmin"
<Directory "/Applications/MAMP/bin/phpMyAdmin">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment