Created
November 7, 2012 22:34
-
-
Save ain/4034980 to your computer and use it in GitHub Desktop.
Symfony 1.4 Doctrine migration base class for checking against existance of the table/field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class SafeDoctrineMigrationBase extends Doctrine_Migration_Base | |
{ | |
public function hasField($table, $field) | |
{ | |
$conn = Doctrine_Manager::connection(); | |
$result = $conn->execute("SHOW COLUMNS FROM $table LIKE '$field'"); | |
$fields = $result->fetchAll(); | |
return !empty($fields); | |
} | |
public function hasTable($table) | |
{ | |
$conn = Doctrine_Manager::connection(); | |
try | |
{ | |
$conn->execute("DESC $table"); | |
} | |
catch (Exception $e) | |
{ | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment