Skip to content

Instantly share code, notes, and snippets.

@vdespa
Last active August 29, 2015 14:19
Show Gist options
  • Save vdespa/ee06bafb128149e4184f to your computer and use it in GitHub Desktop.
Save vdespa/ee06bafb128149e4184f to your computer and use it in GitHub Desktop.
Mysql connect
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL. \n" . mysql_errno($link) . ": " . mysql_error($link). "\n");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("docker",$dbhandle)
or die("Could not select docker." . mysql_errno($link) . ": " . mysql_error($link). "\n");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM docker_data");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "ID:".$row{'id'}." Description:".$row{'description'}."<br>";
}
//close the connection
mysql_close($dbhandle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment