Forum Moderators: coopster

Message Too Old, No Replies

PHP Script For Finding Table Names

         

wfernley

12:52 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi :)

I'm trying to build a script that will find all the table names in my database. This is my current code which of course doesn't work ;)

<?php
$tables_query = mysql_query("SHOW TABLES");
while ($tables = mysql_fetch_assoc($tables_query)) {
print $tables;
}

?>

So I have the query being built and because I am just saying for it to print the variable $tables it just says array. What I am wondering is what do I put for it to print the table names so $tables['?']. Does anyone know?

Thanks in advance for your help.

Wes

ergophobe

3:53 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Check this out

[us2.php.net...]

Timotheos

3:53 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Wes,

For a quick glance use
print_r $tables;

Tim

ergophobe

4:10 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



whoops,

shooting off a little fast today. Yes, the original code should work except that it will just print "array()" or something. To make it more readable when using print_r, echo a "<pre>" ahead of it

echo "<pre>";
print_r $table;
echo "</pre>";

Timotheos

4:19 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ergophobe, I thought that function was pretty cool but alas it's deprecated...

From the manual

Note: The function mysql_list_tables() is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW TABLES [FROM db_name] [LIKE 'pattern'] statement instead.

wfernley

4:36 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey everyone. I just figured it out. I had to put $tables['Tables_in_dbname']. Now it works great :) I guess it would depend on your hosting company. I found this out because I did a query in a program called Navicat and it showed that on the column showing the table names.

Thanks for your posts

Wes

coopster

4:36 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Want to go a step further?

MySQL Database Size [webmasterworld.com]

ergophobe

5:07 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Timotheos. I didn't notice that. I think I need to subscribe to Adam/Jatar_K's executive summary on the PHP changelogs....

They're always coming out with new functions (rarely deprecating though).

Tom

Timotheos

5:33 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[qoute] Adam/Jatar_K's executive summary on the PHP changelogs [/quote]

Eh? Does such a thing really exist?

ergophobe

5:46 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, I meant to put a smilie on that. The executive summary, alas, only exists in his mind. I just said that becuase he's always coming out with things he's picked up through reading every change log as it comes out.

Tom

Timotheos

5:56 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hehe, somehow I knew I was being gullible.