当前位置: 首页>>代码示例>>PHP>>正文


PHP Mysql::insertOnDuplicate方法代码示例

本文整理汇总了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);
 }
开发者ID:,项目名称:,代码行数:14,代码来源:

示例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;
 }
开发者ID:kid17,项目名称:magento2,代码行数:38,代码来源:Configurable.php


注:本文中的Magento\Framework\DB\Adapter\Pdo\Mysql::insertOnDuplicate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。