Skip to content

Instantly share code, notes, and snippets.

@rickumali
Created April 21, 2015 23:03
Show Gist options
  • Save rickumali/56eeb2bacaef0ffdfd8a to your computer and use it in GitHub Desktop.
Save rickumali/56eeb2bacaef0ffdfd8a to your computer and use it in GitHub Desktop.
200 Days of Code: view_users.php
#!/usr/bin/php
<?php
// Created for Boston PHP's 200 Days of Code (4/22/2015).
//
// http://www.meetup.com/bostonphp/events/219831339/
//
// See http://php.net/manual/en/features.commandline.usage.php
require ('mysqli_connect.php');
// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could n
ot connect to MySQL: ' . mysqli_connect_error() );
// Set the encoding...
mysqli_set_charset($dbc, 'utf8');
// Make the query:
$q = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK, display the records.
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo $row['name'] . '-' . $row['dr'] . PHP_EOL;
}
mysqli_free_result ($r); // Free up the resources.
} else { // If it did not run OK.
// Debugging message:
echo mysqli_error($dbc);
} // End of if ($r) IF.
mysqli_close($dbc); // Close the database connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment