This is the Zend_Application_Resource that I wrote to automatically update the schema when making changes to the deployment.
<?php class Cas_Application_Resource_Schema extends Zend_Application_Resource_ResourceAbstract { private function GetScriptsToRun($from, $to) { $application = APPLICATION_PATH . '/configs/sql/'; $result = array(); for($cur = $from + 1; $cur <= $to; $cur++) { $result[] = "{$application}{$cur}.sql"; } return $result; } private function GetLocalVersion() { $options = $this->getOptions(); $version = (int)$options['version']; return $version; } private function GetDbVersion() { $adapter = Zend_Db_Table::getDefaultAdapter(); $metadataTable = new Cas_Model_Table_Metadata; $verQuery = $metadataTable->select()->from($metadataTable, array('Value')); $verQuery->where("{$adapter->quoteIdentifier('Key')} = ?", 'Version'); $dbVersion = $adapter->fetchOne($verQuery); return (int)$dbVersion; } private function RunSqlScript($scriptPath) { $adapter = Zend_Db_Table::getDefaultAdapter(); $contents = file_get_contents($scriptPath); $adapter->query($contents); } private function UpdateVersion() { $metadataTable = new Cas_Model_Table_Metadata; $metadataTable->delete(array("{$metadataTable->getAdapter()->quoteIdentifier('Key')} = ?" => 'Version')); $metadataTable->insert(array('Version' => $this->GetLocalVersion())); } public function init() {
This is because the scripts (for example, configs / sql / 1.sql, configs / sql / 2.sql, etc.) contain several SQL statements, separated by s, with the message:
Zend_Db_Statement_Mysqli_Exception: Mysqli preparation error: you have an error in the SQL syntax; check the manual corresponding to your MySQL server version for the correct syntax used next to ';'
source share