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


PHP AdapterInterface::getConnection方法代码示例

本文整理汇总了PHP中Magento\Framework\DB\Adapter\AdapterInterface::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP AdapterInterface::getConnection方法的具体用法?PHP AdapterInterface::getConnection怎么用?PHP AdapterInterface::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\DB\Adapter\AdapterInterface的用法示例。


在下文中一共展示了AdapterInterface::getConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param array $config
  * @throws LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function __construct($config = [])
 {
     // set a \Zend_Db_Adapter connection
     if (!empty($config['db'])) {
         // convenience variable
         $connection = $config['db'];
         // use an object from the registry?
         if (is_string($connection)) {
             $connection = \Zend::registry($connection);
         }
         // make sure it's a \Magento\Framework\DB\Adapter\AdapterInterface
         if (!$connection instanceof \Magento\Framework\DB\Adapter\AdapterInterface) {
             throw new LocalizedException(new Phrase('db object does not implement \\Magento\\Framework\\DB\\Adapter\\AdapterInterface'));
         }
         // save the connection
         $this->_db = $connection;
         $conn = $this->_db->getConnection();
         if ($conn instanceof \PDO) {
             $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
         }
     } else {
         throw new LocalizedException(new Phrase('db object is not set in config'));
     }
     if (!empty($config['table'])) {
         $this->setTable($config['table']);
     }
     if (!empty($config['id'])) {
         $this->setIdField($config['id']);
     } else {
         $this->setIdField('id');
     }
     if (!empty($config['left'])) {
         $this->setLeftField($config['left']);
     } else {
         $this->setLeftField('left_key');
     }
     if (!empty($config['right'])) {
         $this->setRightField($config['right']);
     } else {
         $this->setRightField('right_key');
     }
     if (!empty($config['level'])) {
         $this->setLevelField($config['level']);
     } else {
         $this->setLevelField('level');
     }
     if (!empty($config['pid'])) {
         $this->setPidField($config['pid']);
     } else {
         $this->setPidField('parent_id');
     }
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:58,代码来源:Tree.php

示例2: insertMultiple

 /**
  * @param string $documentName
  * @param array $records
  * @return bool
  */
 protected function insertMultiple($documentName, $records)
 {
     $bind = [];
     $values = [];
     $colNum = count($records[0]);
     $fields = array_keys($records[0]);
     foreach ($records as $record) {
         foreach ($record as $value) {
             $bind[] = $value;
         }
         $values[] = '(' . implode(',', array_fill(0, $colNum, '?')) . ')';
     }
     if ($values && $fields) {
         $insertSql = sprintf('INSERT INTO %s (%s) VALUES %s', $documentName, sprintf('`%s`', implode('`,`', $fields)), implode(',', $values));
         $statement = $this->resourceAdapter->getConnection()->prepare($insertSql);
         $statement->execute($bind);
     }
     return true;
 }
开发者ID:victor-v-rad,项目名称:data-migration-tool,代码行数:24,代码来源:Mysql.php


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