本文整理匯總了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;
}