Check for table existence before dropping?

Casey picture Casey · Jul 11, 2010 · Viewed 12.4k times · Source

I'm trying to check for the existence of a table before dropping it. I've read through the API documentation for Doctrine_Table and I can't seem to find anything like this. Is there something I'm missing?

I've got code that looks like:

$table = new Doctrine_Table('model_name', $conn);

$export = new Doctrine_Export();

$export->dropTable($table->getTableName());

And the error I get when a table doesn't exist is:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table

Thanks in advance,

Casey

Answer

pleerock picture pleerock · Aug 5, 2013

Doctrine2 method is:

$schemaManager = $this->getDoctrine()->getConnection()->getSchemaManager();
if ($schemaManager->tablesExist(array('users')) == true) {
      // table exists! ...
}