Skip to content

Instantly share code, notes, and snippets.

@bluejaysql
Last active August 29, 2015 14:15
Show Gist options
  • Save bluejaysql/0803355bd98568e6ec6d to your computer and use it in GitHub Desktop.
Save bluejaysql/0803355bd98568e6ec6d to your computer and use it in GitHub Desktop.
Connecting PHP to basic Justice League MySQL db
<?php
define ('dbuser', 'root');
define ('dbpassword', 'password');
define ('dbhost', 'localhost');
define ('dbname', 'jl');
$dbcon = @mysqli_connect (dbhost, dbuser, dbpassword, dbname) OR die ('Could not connect to MySQL: ' . mysqli_connect_error () );
mysqli_set_charset($dbcon, 'utf8');
$result = mysqli_query($dbcon, "SELECT justiceleaguer.alias, justiceleaguer.alterego, species.name FROM justiceleaguer LEFT JOIN species ON justiceleaguer.species = species.id ORDER BY justiceleaguer.id;");
while($row = mysqli_fetch_array($result)) {
echo $row['alias'] . " is " . $row['alterego'] . ", a " . $row['name'] . ". <br>";
}
mysqli_close($dbcon);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment