Hello,
I am new to php, so I bought a book to teach myself this language. I am trying to create a connection to a database and list the names of the tables it contains. The database has only one table. When I comment out all but the mysql_connect and mysql_select_db statements (and their corresponding echo statements), the code works as expected. However, as soon as I uncomment the mysql_query statement Firefox presents a dialog to open or save the php file. When using Chrome, it shows ‘Error 324 (net::ERR_EMPTY_RESPONSE).’ As I read up on the mysql_query statement, the documentation states that you shouldn’t use a ‘;’ following the show tables command, but the book shows one. Whether I include it or not, though, the problem remains.
Thank you in advance for the assistance.
The code is:
[php]
$con = mysql_connect(“localhost”,“myusername”,“mypassword”);
if (!$con) {
die ("
Error connecting to database: " . mysql_error() . “
”);}
echo "<p>Connected to MySQL!</p>";
mysql_select_db("fgexample",$con) or die("<p>Error selecting the database mysql: " . mysql_error() . "</p>");
echo "<p>Connected to MySQL, using database mysql</p>";
$result = mysql_query("show tables;");
if (!$result) {
die("<p>Error in listing tables: " . mysql_error() . "</p>");
}
echo "<p>Tables in database: </p>";
echo "<ul>";
while ($row = mysql_fetch_row($result)) {
echo "<li>Table: " . $row[0] . "</li>";
}
echo "</ul>";
[/php]