本文整理汇总了PHP中Magento\Framework\DB\Adapter\Pdo\Mysql::insertOnDuplicate方法的典型用法代码示例。如果您正苦于以下问题:PHP Mysql::insertOnDuplicate方法的具体用法?PHP Mysql::insertOnDuplicate怎么用?PHP Mysql::insertOnDuplicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DB\Adapter\Pdo\Mysql
的用法示例。
在下文中一共展示了Mysql::insertOnDuplicate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInsertOnDuplicateWithQuotedColumnName
/**
* Test that column names are quoted in ON DUPLICATE KEY UPDATE section
*/
public function testInsertOnDuplicateWithQuotedColumnName()
{
$table = 'some_table';
$data = ['index' => 'indexValue', 'row' => 'rowValue', 'select' => 'selectValue', 'insert' => 'insertValue'];
$fields = ['select', 'insert'];
$sqlQuery = "INSERT INTO `some_table` (`index`,`row`,`select`,`insert`) VALUES (?, ?, ?, ?) " . "ON DUPLICATE KEY UPDATE `select` = VALUES(`select`), `insert` = VALUES(`insert`)";
$stmtMock = $this->getMock('Zend_Db_Statement_Pdo', [], [], '', false);
$bind = ['indexValue', 'rowValue', 'selectValue', 'insertValue'];
$this->_adapter->expects($this->once())->method('query')->with($sqlQuery, $bind)->will($this->returnValue($stmtMock));
$this->_adapter->insertOnDuplicate($table, $data, $fields);
}
示例2: _insertData
/**
* Collected link data insertion.
*
* @return $this
* @throws \Zend_Db_Exception
*/
protected function _insertData()
{
$mainTable = $this->_resource->getTableName('catalog_product_super_attribute');
$labelTable = $this->_resource->getTableName('catalog_product_super_attribute_label');
$priceTable = $this->_resource->getTableName('catalog_product_super_attribute_pricing');
$linkTable = $this->_resource->getTableName('catalog_product_super_link');
$relationTable = $this->_resource->getTableName('catalog_product_relation');
$mainData = [];
foreach ($this->_superAttributesData['attributes'] as $productId => $attributesData) {
foreach ($attributesData as $attrId => $row) {
$row['product_id'] = $productId;
$row['attribute_id'] = $attrId;
$mainData[] = $row;
}
}
if ($mainData) {
$this->_connection->insertOnDuplicate($mainTable, $mainData);
}
if ($this->_superAttributesData['labels']) {
$this->_connection->insertOnDuplicate($labelTable, $this->_superAttributesData['labels']);
}
if ($this->_superAttributesData['pricing']) {
$this->_connection->insertOnDuplicate($priceTable, $this->_superAttributesData['pricing'], ['is_percent', 'pricing_value']);
}
if ($this->_superAttributesData['super_link']) {
$this->_connection->insertOnDuplicate($linkTable, $this->_superAttributesData['super_link']);
}
if ($this->_superAttributesData['relation']) {
$this->_connection->insertOnDuplicate($relationTable, $this->_superAttributesData['relation']);
}
return $this;
}