當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。