Here's some code that can be used to dump out all of the information in one of your MySql database tables. It's useful to pick through and see how things work. Just be sure to change the host, user, pwd, database, and table names before you start it up.
(datadump.php)
(datadump.php)
<html><head><title>MySQL Table Viewer</title></head><body>
<?php
$db_host = 'localhost';
$db_user = 'INSERT USER NAME';
$db_pwd = 'INSERT PASSWORD';
$database = 'INSERT DATABASE NAME';
$table = 'INSERT TABLE NAME';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
Tags
My Blog Links
Recent Entries
-
-
What's a WebAPI anyway? How can I use one? Are https get requests easy in ruby?
on Oct 12 2011 04:38 PM
-
03_View MySql tables with PHPon Jun 11 2011 03:09 PM
-
-
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
Categories
|
|



Leave Comment









|