Hi,
I'm trying to return a list of all tables from my database by using the "show tables from <dbname>" query, and fetching the returned rows from the result handle.
However, although the first table is correctly returned, that's it, it doesn't return any of the others.
I'm read in some places that this particular query will only return tables with data in them, however more of the tables in my database have rows in them, and these are not being returned. I don't know if this query returns the tables in alphabetical order, however the table returned by the query is the first table alphabetically.
Bizarrely, if I check the number of rows returned using mysql_num_rows, it returns the correct number of tables in the selected database, however the row fetch returns false after only the first table.
I've spent a while trying to work this out, but it sort of eludes me, as if its going on at a lower level that you don't have access to in PHP.
Any ideas please.
Many thanks
Problems with "show tables from $dbname" query
Moderator: General Moderators
Code: Select all
// Query to obtain all tables
if(!$this->m_database->SQLQuery("show tables from ".LS_DATABASE_NAME))
{
return false;
}
while( $row = $this->m_database->FetchRow() )
{
// cycle through tables
}Code: Select all
public function SQLQuery( $query )
{
// Obtain the SQL query resultset
if(!($this->m_result = mysql_query( $query )))
{
return false;
}
return true;
}
public function FetchRow()
{
// Obtain the next mysql row
$row = mysql_fetch_row( $this->m_result );
return $row;
}?
Sorry, my mistake. What was happening was I was calling a function in my database class to export each table as a CSV file. This function itself was calling the SQLQuery function, which was messing up the FetchRow function that was cycling through the table names.
I have to get used to using classes in PHP as opposed to C++.
Sorry for the mixup,
Many thanks.
I have to get used to using classes in PHP as opposed to C++.
Sorry for the mixup,
Many thanks.