perrin21 Posted August 15, 2007 Share Posted August 15, 2007 Hey all! 'k, so I'm trying CLI PHP for the first time..., The project I've been handed requires a display of all tables in said database. How do I proceed??? thanks for any help, in this regard! Quote Link to comment https://forums.phpfreaks.com/topic/65052-show-tables-using-php/ Share on other sites More sharing options...
thedarkwinter Posted August 15, 2007 Share Posted August 15, 2007 Hi If you want to put the table names into an array: <?php mysql_connect("localhost", "user", "pass"); mysql_select_db("my_table"); $tables = array(); $result= mysql_query("show tables;"); while ($row = mysql_fetch_row($result)) { array_push($tables, $row[0]);} print_r($tables); ?> cheers, tdw Quote Link to comment https://forums.phpfreaks.com/topic/65052-show-tables-using-php/#findComment-324683 Share on other sites More sharing options...
perrin21 Posted August 16, 2007 Author Share Posted August 16, 2007 thanks for the help tdw... but I eventually solved the problem using: <?php ... $dbc = mysql_connect($ip,$user,$pass) or die(mysql_error()); mysql_select_db($db,$dbc) or die(mysql_error()); $sql = "SHOW TABLES FROM $db"; $result = mysql_query($sql, $dbc) or die(mysql_error()); // displaying tables if ($myrow = mysql_fetch_array($result)) { do{ echo " Table {$myrow[0]}\n"; } while($myrow = mysql_fetch_array($result)); }// end if ... ?> Once again thanks!!!! Regards DeeJay Quote Link to comment https://forums.phpfreaks.com/topic/65052-show-tables-using-php/#findComment-325610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.