ArtcoInc Posted April 27, 2015 Share Posted April 27, 2015 Is there currently a function in osC to check to see if a table exists in the database? I have found a number of code examples on the web, but don't want to have to re-invent the wheel if I don't have to ;) Thanks! Malcolm Link to comment Share on other sites More sharing options...
oscMarket Posted April 27, 2015 Share Posted April 27, 2015 $CheckTable = tep_db_query("SHOW TABLES LIKE 'products'"); if( tep_db_num_rows($CheckTable) > 0 ) echo 'Table exists'; Link to comment Share on other sites More sharing options...
ArtcoInc Posted April 27, 2015 Author Share Posted April 27, 2015 @@wHiTeHaT Thanks! Malcolm Link to comment Share on other sites More sharing options...
ArtcoInc Posted April 27, 2015 Author Share Posted April 27, 2015 @@wHiTeHaT While I don't understand it, this works fine. Thanks! I created a new, empty table called 'test'. Then, using this code: <?php $CheckTable = tep_db_query("SHOW TABLES LIKE 'test'"); if( tep_db_num_rows($CheckTable) > 0 ) { echo 'Table exists <br />'; echo tep_db_num_rows($CheckTable) . '<br />'; } else { echo 'Table does not exist <br />'; } ?> it returns: Table exists 1 yet, phpMyAdmin shows that there are zero rows. I'm confused ... :wacko: Malcolm Link to comment Share on other sites More sharing options...
♥kymation Posted April 28, 2015 Share Posted April 28, 2015 tep_db_num_rows() returns the number of rows in the query, not the number of rows in the table. Since there is one table named test, the query returns one row representing that one table. If you want to know the number of rows in the table, you'll need a new query like: $test = tep_db_query("select * from 'test'"); echo tep_db_num_rows($test) . '<br />'; Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.