Last active
March 14, 2022 16:50
-
-
Save carlaizumibamford/d9404c1f1220d673d85e to your computer and use it in GitHub Desktop.
Debugging When Establishing A MySQL Database
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 | |
$con = mysql_connect('localhost', 'root', '1234'); | |
if (!$con) { | |
exit('Cannot connect database.'); | |
} | |
$result = mysql_select_db('phpdb', $con); | |
if (!$result) { | |
exit('Cannot select database.'); | |
} | |
$result = mysql_query('SET NAMES utf8', $con); | |
if (!$result) { | |
exit('Cannot define character code.'); | |
} | |
$result = mysql_query('SELECT * FROM table', $con); | |
while ($data = mysql_fetch_array($result)) { | |
echo '<p>' . $data['id'] . ':' . $data['name'] . ':' . $data['email'] . "</p>\n"; | |
} | |
$con = mysql_close($con); | |
if (!$con) { | |
exit('Cannot end database connection.'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment