Jump to content

Finding tables in DB


ShaolinF

Recommended Posts

mysql_list_tables — List tables in a MySQL database

 

resource mysql_list_tables  ( string $database  [, resource $link_identifier  ] )

 

Retrieves a list of table names from a MySQL database.

 

http://au2.php.net/mysql

 

Regards ACE

 

 

Link to comment
https://forums.phpfreaks.com/topic/110660-finding-tables-in-db/#findComment-567699
Share on other sites

Thanks

 

Everytime I try it I get a mydb could not be  converted to string.

		$sql = "SHOW TABLES FROM $mydb" or die (mysql_error());
		$result = mysql_query($sql);

		while ($row = mysql_fetch_row($result)) {
		    echo "Table: {$row[1]}\n";
		}

 

Assuming you have the $mydb variable's value set elsewhere, this should work for you.

 

$query = "SHOW TABLES FROM " . $mydb;
$result = mysql_query( $query );
while( $array = mysql_fetch_array( $result, MYSQL_ASSOC) )
{
print_r( $array );
}

Link to comment
https://forums.phpfreaks.com/topic/110660-finding-tables-in-db/#findComment-567831
Share on other sites

It is a mysql connect object.

 

If it's just the database name, it should work in the query, if it is a

$mydb = mysql_connect( $db_host, $db_user, $db_pass ); 

statement, it will not. That means you will have to use a variable containing only the database name. Try echoing the $sql variable to see what you are sending as a db query.

Link to comment
https://forums.phpfreaks.com/topic/110660-finding-tables-in-db/#findComment-568783
Share on other sites

It gives me an error. Basically the $mydb is an object oriented instance. When I want to call a table from the DB I use $mydb->tableName - What Im trying to do is to get all the db tables to display but since $mydb is an object the I don't know how to grab all the table names and output them..

Link to comment
https://forums.phpfreaks.com/topic/110660-finding-tables-in-db/#findComment-569324
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.