本文整理汇总了PHP中SqlParser::parseString方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlParser::parseString方法的具体用法?PHP SqlParser::parseString怎么用?PHP SqlParser::parseString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlParser
的用法示例。
在下文中一共展示了SqlParser::parseString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* Main method builds all the targets for a typical propel project.
*/
public function main()
{
$manager = new MigrationManager();
$manager->setConnections($this->getGeneratorConfig()->getBuildConnections());
$manager->setMigrationTable($this->getMigrationTable());
$manager->setMigrationDir($this->getOutputDirectory());
if (!($nextMigrationTimestamp = $manager->getFirstUpMigrationTimestamp())) {
$this->log('All migrations were already executed - nothing to migrate.');
return false;
}
$timestamps = $manager->getValidMigrationTimestamps();
if (count($timestamps) > 1) {
$this->log(sprintf('%d migrations to execute', count($timestamps)));
}
foreach ($timestamps as $timestamp) {
$this->log(sprintf('Executing migration %s up', $manager->getMigrationClassName($timestamp)));
$migration = $manager->getMigrationObject($timestamp);
if (false === $migration->preUp($manager)) {
$this->log('preUp() returned false. Aborting migration.', Project::MSG_ERR);
return false;
}
foreach ($migration->getUpSQL() as $datasource => $sql) {
$connection = $manager->getConnection($datasource);
$this->log(sprintf('Connecting to database "%s" using DSN "%s"', $datasource, $connection['dsn']), Project::MSG_VERBOSE);
$pdo = $manager->getPdoConnection($datasource);
$res = 0;
$statements = SqlParser::parseString($sql);
foreach ($statements as $statement) {
try {
$this->log(sprintf('Executing statement "%s"', $statement), Project::MSG_VERBOSE);
$stmt = $pdo->prepare($statement);
$stmt->execute();
$res++;
} catch (PDOException $e) {
$this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR);
// continue
}
}
if (!$res) {
$this->log('No statement was executed. The version was not updated.');
$this->log(sprintf('Please review the code in "%s"', $manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($timestamp)));
$this->log('Migration aborted', Project::MSG_ERR);
return false;
}
$this->log(sprintf('%d of %d SQL statements executed successfully on datasource "%s"', $res, count($statements), $datasource));
$manager->updateLatestMigrationTimestamp($datasource, $timestamp);
$this->log(sprintf('Updated latest migration date to %d for datasource "%s"', $timestamp, $datasource), Project::MSG_VERBOSE);
}
$migration->postUp($manager);
}
$this->log('Migration complete. No further migration to execute.');
}