Jump to content

Finding tables in DB


ShaolinF

Recommended Posts

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";
		}

Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.