By information_schema
of mysql it is possible to access all the tables of a database:
SELECT table_name FROM information_schema.tables WHERE table_schema = 'data_base'
AND table_name = 'nome_da_tabela'
After the query, use the function / method of the bank driver that retries the amount of bank records:
count () (generically)
rowCount () (PDO)
mysqli_num_rows () (mysqli)
$db = new PDO('mysql:host=localhost dbname=test','usuario', 'senha');
$sql = 'SELECT table_name FROM information_schema.tables WHERE table_schema = :database
AND table_name = :tabela';
$stmt = $db->prepare($sql);
$stmt->bindValue(':database', 'test';
$stmt->bindValue(':tabele', 'bananas';
$stmt->execute();
$tabelas = $stmt->rowCount();
if($tabelas >= 1 ){
echo 'tabela valida';
//efetuar select
}else{
echo 'tabela invalida';
//efetuar um create table?
}
about information_schema