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
[SOLVED]To get DB table names
[SOLVED]To get DB table names
Last edited by vilkis on Tue May 26, 2009 8:53 pm, edited 1 time in total.
Re: To get DB table names
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:
You will find this in the defaultadmin.php program.
Thanks to the author ortegaj of the module.
Duketown
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");
}
Thanks to the author ortegaj of the module.
Duketown
Re: To get DB table names
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
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
vilkis,
I don't use PostgreSQL, but can't you use something like the following (via search of google):
Duketown
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';
Re: To get DB table names
In my module I use this:
Albyglobal $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];
Re: To get DB table names
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
vilkis