Page 1 of 1
[SOLVED]To get DB table names
Posted: Wed May 20, 2009 8:22 am
by vilkis
Hi,
Is there a way to get names of tables that exist in a database? As I know Adodb Lite included in CMSMS has not such a function.
vilkis
Re: To get DB table names
Posted: Thu May 21, 2009 6:35 pm
by Duketown
vilkis,
There are maybe more ways to get this done, but when you look in module AfterMM you will find the (astonishing simple) part that is as follows:
Code: Select all
$query = "show tables";
$dbresult = $db->Execute($query);
$rowclass = 'row1';
while ($dbresult && $row = $dbresult->FetchRow())
{
$onerow = new stdClass();
$tablesIn = 'Tables_in_' . substr(cms_db_prefix(),0,strlen(cms_db_prefix()) - 1 );
$onerow->name = $this->CreateLink($id, 'showStructure', $returnid, $row[$tablesIn], array('tablenames'=>$row[$tablesIn]));
$onerow->rowclass = $rowclass;
$entryarray[] = $onerow;
($rowclass=="row1"?$rowclass="row2":$rowclass="row1");
}
You will find this in the defaultadmin.php program.
Thanks to the author ortegaj of the module.
Duketown
Re: To get DB table names
Posted: Thu May 21, 2009 6:49 pm
by vilkis
Hi,
Thank you for replay.
I think it is not valid for PostgreSQL DB. I'm looking for universal tool...
I think we can press devs of core to include a full version of adodb lite...

vilkis
Re: To get DB table names
Posted: Thu May 21, 2009 7:32 pm
by Duketown
vilkis,
I don't use PostgreSQL, but can't you use something like the following (via search of google):
Code: Select all
select * from pg_tables where tableowner = 'ME';
Duketown
Re: To get DB table names
Posted: Tue May 26, 2009 3:06 pm
by alby
In my module I use this:
global $gCms;
$qc='';
switch($gCms->config['dbms'])
{
case 'mysql':
case 'mysqli':
$qc = "SHOW TABLES";
break;
case 'postgres7':
$qc = "select table_name from information_schema.tables where table_schema='public'";
break;
}
if(empty($qc)) die('No SQL driver in config.php (mysql,mysqli,postgres7)?');
$db =& $this->GetDb();
$db->SetFetchMode(ADODB_FETCH_NUM);
$dbresult = $db->Execute($qc);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
if(!$dbresult) die('Error in sql show: '.$qc);
$tables=array();
while($dbresult && $row=$dbresult->FetchRow())
$tables[] = $row[0];
Alby
Re: To get DB table names
Posted: Tue May 26, 2009 5:11 pm
by vilkis
Thanks for responses. Alby, I will use your code if I do not find how to implement meta module for adodb lite without hacking CMSMS.
vilkis