Created
January 27, 2012 03:19
-
-
Save krisys/1686782 to your computer and use it in GitHub Desktop.
Example to show php connecting to mysql db.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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