Skip to content

Instantly share code, notes, and snippets.

@krisys
Created January 27, 2012 03:19
Show Gist options
  • Save krisys/1686782 to your computer and use it in GitHub Desktop.
Save krisys/1686782 to your computer and use it in GitHub Desktop.
Example to show php connecting to mysql db.
<?php
/* source: www.w3schools.com */
$con = mysql_connect("localhost","peter","abc123");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment