本文整理汇总了PHP中Statement::getPreparedStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP Statement::getPreparedStatement方法的具体用法?PHP Statement::getPreparedStatement怎么用?PHP Statement::getPreparedStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement::getPreparedStatement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgrade
/**
* Perform upgrade for a table, by comparing one table to an old version
* of the same table
*
* @param Table $old_table
*/
public function upgrade(Table $old_table)
{
if ($old_table->getVersion() != $this->getVersion() - 1) {
throw new Exception('Cannot upgrade from ' . get_class($old_table) . ' version ' . $old_table->getVersion() . ', must be version ' . ($this->getVersion() - 1));
}
$old_columns = $old_table->getColumns();
$new_columns = $this->getColumns();
$added_columns = \array_diff_key($new_columns, $old_columns);
$altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
$dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
$sqls = array();
foreach ($added_columns as $column => $details) {
$sqls[] = $this->_getAddColumnSQL($column, $details);
}
if (count($sqls)) {
foreach ($sqls as $sqlStmt) {
$statement = Statement::getPreparedStatement($sqlStmt);
$res = $statement->performQuery('alter');
}
}
$this->_migrateData($old_table);
$sqls = array();
foreach ($altered_columns as $column => $details) {
if (in_array($column, $dropped_columns)) {
continue;
}
$sqls[] = $this->_getAlterColumnSQL($old_columns[$column], $new_columns[$column]);
}
foreach ($dropped_columns as $details) {
$sqls[] = $this->_getDropColumnSQL($details);
}
if (count($sqls)) {
foreach ($sqls as $sqlStmt) {
$statement = Statement::getPreparedStatement($sqlStmt);
$res = $statement->performQuery('alter');
}
}
}
示例2: upgrade
/**
* Perform upgrade for a table, by comparing one table to an old version
* of the same table
*
* @param Table $old_table
*/
public function upgrade(Table $old_table)
{
$old_columns = $old_table->getColumns();
$new_columns = $this->getColumns();
$added_columns = \array_diff_key($new_columns, $old_columns);
$altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
$dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
$sqls = array();
foreach ($added_columns as $details) {
$sqls[] = $this->_getAddColumnSQL($details);
}
if (count($sqls)) {
foreach ($sqls as $sqlStmt) {
if ($sqlStmt) {
Statement::getPreparedStatement($sqlStmt)->performQuery();
}
}
}
$this->_migrateData($old_table);
$sqls = array();
foreach ($altered_columns as $column => $details) {
if (in_array($column, $dropped_columns)) {
continue;
}
$sqls[] = $this->_getAlterColumnSQL($new_columns[$column]);
$altersql = $this->_getAlterColumnDefaultSQL($new_columns[$column]);
if ($altersql) {
$sqls[] = $altersql;
}
}
foreach ($dropped_columns as $details) {
$sqls[] = $this->_getDropColumnSQL($details);
}
if (count($sqls)) {
foreach ($sqls as $sqlStmt) {
if ($sqlStmt) {
Statement::getPreparedStatement($sqlStmt)->performQuery();
}
}
}
}