php Zend-Db-Adapter-Adapter类(方法)实例源码

下面列出了php Zend-Db-Adapter-Adapter 类(方法)源码代码实例,从而了解它的用法。

作者:baptistecost    项目:mon-partenair   
public function find($params)
 {
     $sql = new Sql($this->getAdapter());
     $select = new Select();
     $select->from($params['from']);
     if (!empty($params['columns'])) {
         $select->columns($params['columns']);
     }
     foreach ($params['where'] as $where) {
         $select->where($where);
     }
     foreach ($params['joins'] as $join) {
         if (empty($join['columns'])) {
             $join['columns'] = Select::SQL_STAR;
         }
         if (empty($join['type'])) {
             $join['type'] = Select::JOIN_INNER;
         }
         $select->join($join['name'], $join['on'], $join['columns'], $join['type']);
     }
     $query = $sql->getSqlStringForSqlObject($select);
     $results = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
     $data = $results->toArray();
     if (empty($data)) {
         return false;
     } else {
         if (count($data) == 1) {
             return $data[0];
         } else {
             return $data;
         }
     }
 }

作者:t4we    项目:queu   
public function onDispatch(MvcEvent $e)
 {
     if (!$e->getRequest() instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console!');
     }
     $table = new Ddl\CreateTable('queue_messages');
     $table->addColumn(new Ddl\Column\Integer('id', false, null, ['autoincrement' => true]));
     $table->addColumn(new Ddl\Column\Varchar('queue_name', 100));
     $table->addColumn(new Ddl\Column\Integer('status', false));
     $table->addColumn(new Ddl\Column\Varchar('options', 250));
     $table->addColumn(new Ddl\Column\Text('message', null, true));
     $table->addColumn(new Ddl\Column\Text('output', null, true));
     $table->addColumn(new Ddl\Column\Datetime('started_dt', true));
     $table->addColumn(new Ddl\Column\Datetime('finished_dt', true));
     $table->addColumn(new Ddl\Column\Datetime('created_dt', false));
     $table->addColumn(new Ddl\Column\Datetime('updated_dt', true));
     $table->addConstraint(new Ddl\Constraint\PrimaryKey('id'));
     $sql = new Sql($this->dbAdapter);
     try {
         $this->dbAdapter->query($sql->buildSqlString($table), DbAdapter::QUERY_MODE_EXECUTE);
     } catch (\Exception $e) {
         // currently there are no db-independent way to check if table exists
         // so we assume that table exists when we catch exception
     }
 }

作者:pgiacomett    项目:zf2rapi   
/**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // load autoload configuration from project
     $config = ConfigFactory::fromFiles(glob($this->params->projectConfigDir . '/autoload/{,*.}{global,development,local}.php', GLOB_BRACE));
     // check for db config
     if (empty($config) || !isset($config['db'])) {
         $this->console->writeFailLine('task_crud_check_db_connection_no_config');
         return 1;
     }
     // create db adapter instance
     try {
         $dbAdapter = new Adapter($config['db']);
     } catch (InvalidArgumentException $e) {
         $this->console->writeFailLine('task_crud_check_db_connection_config_inconsistent');
         return 1;
     }
     // connect to database
     try {
         $connection = $dbAdapter->getDriver()->getConnection()->connect();
     } catch (RuntimeException $e) {
         $this->console->writeFailLine('task_crud_check_db_connection_failed');
         return 1;
     }
     $this->params->dbAdapter = $dbAdapter;
     return 0;
 }

作者:robak    项目:Location   
private function create(SqlInterface $table)
 {
     try {
         $sql = new Sql($this->dbAdapter);
         $this->dbAdapter->query($sql->buildSqlString($table), Adapter::QUERY_MODE_EXECUTE);
     } catch (PDOException $e) {
         $message = $e->getMessage() . PHP_EOL;
     }
 }

作者:KIVagan    项目:console-tool   
/**
  * 
  * @param string $tableName
  * @param array $data
  * @return bool
  */
 public function insert($tableName, array $data)
 {
     $sql = new Sql($this->adapter);
     $insert = $sql->insert($tableName);
     $insert->values($data);
     $sqlString = $sql->getSqlStringForSqlObject($insert);
     $results = $this->adapter->query($sqlString, Adapter::QUERY_MODE_EXECUTE);
     return $results;
 }

作者:huanhuashenglin    项目:ipc2013-testin   
/**
  * Get Database Connection
  *
  * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
  */
 public function getConnection()
 {
     if (!$this->connection) {
         $dbConfig = array('driver' => 'pdo', 'dsn' => 'mysql:dbname=ipc2013.testing.test;host=localhost;charset=utf8', 'user' => 'ipc2013', 'pass' => 'ipc2013');
         $this->adapter = new Adapter($dbConfig);
         $this->connection = $this->createDefaultDBConnection($this->adapter->getDriver()->getConnection()->getResource(), 'ipc2013.testing.test');
     }
     return $this->connection;
 }

作者:t4we    项目:migration   
public function executeQuery($sql)
 {
     if (!$this->dbAdapter) {
         /** @var Adapter dbAdapter */
         $this->dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     }
     /** @var ResultSet $photos */
     return $this->dbAdapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
 }

作者:haoyanfe    项目:zf   
protected function processExpression(ExpressionInterface $expression, PlatformInterface $platform, Adapter $adapter = null, $namedParameterPrefix = null)
 {
     // static counter for the number of times this method was invoked across the PHP runtime
     static $runtimeExpressionPrefix = 0;
     if ($adapter && (!is_string($namedParameterPrefix) || $namedParameterPrefix == '')) {
         $namedParameterPrefix = sprintf('expr%04dParam', ++$runtimeExpressionPrefix);
     }
     $sql = '';
     $statementContainer = new StatementContainer();
     $parameterContainer = $statementContainer->getParameterContainer();
     // initialize variables
     $parts = $expression->getExpressionData();
     $expressionParamIndex = 1;
     foreach ($parts as $part) {
         // if it is a string, simply tack it onto the return sql "specification" string
         if (is_string($part)) {
             $sql .= $part;
             continue;
         }
         if (!is_array($part)) {
             throw new Exception\RuntimeException('Elements returned from getExpressionData() array must be a string or array.');
         }
         // process values and types (the middle and last position of the expression data)
         $values = $part[1];
         $types = isset($part[2]) ? $part[2] : array();
         foreach ($values as $vIndex => $value) {
             if (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_IDENTIFIER) {
                 $values[$vIndex] = $platform->quoteIdentifierInFragment($value);
             } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE) {
                 // if prepareType is set, it means that this particular value must be
                 // passed back to the statement in a way it can be used as a placeholder value
                 if ($adapter) {
                     $name = $namedParameterPrefix . $expressionParamIndex++;
                     $parameterContainer->offsetSet($name, $value);
                     $values[$vIndex] = $adapter->getDriver()->formatParameterName($name);
                     continue;
                 }
                 // if not a preparable statement, simply quote the value and move on
                 $values[$vIndex] = $platform->quoteValue($value);
             } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_LITERAL) {
                 $values[$vIndex] = $value;
             } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_SELECT) {
                 // process sub-select
                 if ($adapter) {
                     $values[$vIndex] = '(' . $this->processSubSelect($value, $platform, $adapter, $statementContainer->getParameterContainer()) . ')';
                 } else {
                     $values[$vIndex] = '(' . $this->processSubSelect($value, $platform) . ')';
                 }
             }
         }
         // after looping the values, interpolate them into the sql string (they might be placeholder names, or values)
         $sql .= vsprintf($part[0], $values);
     }
     $statementContainer->setSql($sql);
     return $statementContainer;
 }

作者:gridguy    项目:zor   
/**
  * Load config from db-adapter
  *
  * @param \Zend\Db\Adapter\Adapter $db
  * @return array
  */
 protected function loadConfig()
 {
     if (empty($this->dbAdapter)) {
         return $this->config;
     }
     $platform = $this->dbAdapter->getPlatform();
     $driver = $this->dbAdapter->getDriver();
     $query = $this->dbAdapter->query('
         SELECT ' . $platform->quoteIdentifier('value') . '
           FROM ' . $platform->quoteIdentifier('settings') . '
          WHERE ' . $platform->quoteIdentifier('key') . '
              = ' . $platform->quoteValue('ini-cache') . '
            AND ' . $platform->quoteIdentifier('type') . '
              = ' . $platform->quoteValue('ini-cache') . '
          LIMIT 1
     ');
     $this->config = array();
     $result = $query->execute();
     if ($result->getAffectedRows() > 0) {
         foreach ($result as $cache) {
             $this->config = ArrayUtils::merge($this->config, (array) unserialize($cache['value']));
         }
     } else {
         $query = $this->dbAdapter->query('
             SELECT ' . $platform->quoteIdentifier('key') . ',
                    ' . $platform->quoteIdentifier('value') . '
               FROM ' . $platform->quoteIdentifier('settings') . '
              WHERE ' . $platform->quoteIdentifier('type') . '
                  = ' . $platform->quoteValue('ini') . '
         ');
         foreach ($query->execute() as $pair) {
             $key = (string) $pair['key'];
             $value = (string) $pair['value'];
             $entry = array();
             $curr =& $entry;
             foreach (explode('.', $key) as $sub) {
                 $curr[$sub] = null;
                 $curr =& $curr[$sub];
             }
             $curr = $value;
             $this->config = ArrayUtils::merge($this->config, $entry);
         }
         $query = $this->dbAdapter->query('
             INSERT INTO ' . $platform->quoteIdentifier('settings') . '
                         ( ' . $platform->quoteIdentifier('key') . ',
                           ' . $platform->quoteIdentifier('value') . ',
                           ' . $platform->quoteIdentifier('type') . ' )
                  VALUES ( ' . $driver->formatParameterName('key') . ',
                           ' . $driver->formatParameterName('value') . ',
                           ' . $driver->formatParameterName('type') . ' )
         ');
         $query->execute(array('key' => 'ini-cache', 'value' => serialize($this->config), 'type' => 'ini-cache'));
     }
     $this->dbAdapter = null;
     return $this->config;
 }

作者:anillaogi01    项目:zend-admi   
public function selectCategoryOptions()
 {
     $adapter = new Adapter(array('driver' => 'mysqli', 'host' => 'localhost', 'port' => '3306', 'dbname' => 'zndemo', 'username' => 'root', 'password' => ''));
     $result = $adapter->getDriver()->getConnection()->execute('select id,name from categories where status=1');
     $selectData = array(0 => '--Select Category--');
     foreach ($result as $res) {
         $selectData[$res['id']] = $res['name'];
     }
     return $selectData;
 }

作者:rikai    项目:zf   
/**
  * Create source from adapter
  * 
  * @param  Adapter $adapter
  * @return Source\InformationSchemaMetadata 
  */
 protected function createSourceFromAdapter(Adapter $adapter)
 {
     switch ($adapter->getPlatform()->getName()) {
         case 'MySQL':
         case 'SQLServer':
             return new Source\InformationSchemaMetadata($adapter);
         case 'SQLite':
             return new Source\SqliteMetadata($adapter);
     }
     throw new \Exception('cannot create source from adapter');
 }

作者:haoyanfe    项目:zf   
public function __construct(Adapter $adapter)
 {
     $this->adapter = $adapter;
     $platform = $adapter->getPlatform();
     switch (strtolower($platform->getName())) {
         case 'sqlserver':
             $platform = new SqlServer\SqlServer();
             $this->decorators = $platform->decorators;
             break;
         default:
     }
 }

作者:projectsmahendr    项目:blogge   
/**
  *
  */
 public function setUpMockedAdapter()
 {
     $this->mockedDbAdapterDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $this->mockedDbAdapterPlatform = $this->getMock('\\Zend\\Db\\Adapter\\Platform\\PlatformInterface', array());
     $this->mockedDbAdapterStatement = $this->getMock('\\Zend\\Db\\Adapter\\Driver\\StatementInterface', array());
     $this->mockedDbAdapterPlatform->expects($this->any())->method('getName')->will($this->returnValue('null'));
     $this->mockedDbAdapter = $this->getMockBuilder('\\Zend\\Db\\Adapter\\Adapter')->setConstructorArgs(array($this->mockedDbAdapterDriver, $this->mockedDbAdapterPlatform))->getMock(array('getPlatform'));
     $this->mockedDbAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue($this->mockedDbAdapterPlatform));
     $this->mockedDbSql = $this->getMockBuilder('\\Zend\\Db\\Sql\\Sql')->setConstructorArgs(array($this->mockedDbAdapter))->setMethods(array('prepareStatementForSqlObject'))->getMock();
     $this->mockedDbSql->expects($this->any())->method('prepareStatementForSqlObject')->will($this->returnValue($this->mockedDbAdapterStatement));
     $this->mockedDbSqlPlatform = $this->getMockBuilder('\\Zend\\Db\\Sql\\Platform\\Platform')->setConstructorArgs(array($this->mockedDbAdapter))->getMock();
 }

作者:dragonmantan    项目:dockerfordevs-ap   
public function save(Queue $queue)
 {
     if ($queue->getId()) {
         $query = $this->dbAdapter->query('UPDATE `queues` SET `name` = :name WHERE `id = :id`');
         $query->execute($queue->getArrayCopy());
     } else {
         $query = $this->dbAdapter->query("INSERT INTO `queues` (`name`) VALUES (:name)");
         $query->execute(['name' => $queue->getName()]);
         $queue->setId($this->dbAdapter->getDriver()->getLastGeneratedValue());
     }
     return $queue;
 }

作者:Baf    项目:Zend-For   
protected function processOffset(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null)
 {
     if ($this->offset === null) {
         return null;
     }
     if ($adapter) {
         $parameterContainer->offsetSet('offset', $this->offset, ParameterContainer::TYPE_INTEGER);
         return array($adapter->getDriver()->formatParameterName('offset'));
     } else {
         return array($this->offset);
     }
 }

作者:robocode    项目:solublecomponent   
/**
  * Automatically create source from adapter
  *
  * @throws Exception\UnsupportedDriverException
  * @param \Zend\Db\Adapter\Adapter $adapter
  * @param string $schema database schema to use or null to current schema defined by the adapter
  * @return \Soluble\Db\Metadata\Source\AbstractSource
  */
 protected function createSourceFromAdapter(Adapter $adapter, $schema = null)
 {
     $adapter_name = strtolower($adapter->getPlatform()->getName());
     switch ($adapter_name) {
         case 'mysql':
             $source = new Source\Mysql\InformationSchema($adapter, $schema);
             break;
         default:
             throw new Exception\UnsupportedDriverException("Currently only MySQL is supported, driver set '{$adapter_name}'");
     }
     return $source;
 }

作者:FiftyNin    项目:ScpperD   
/**
  * Create db adapter service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return Adapter
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $result = new Adapter($config['db']);
     if (defined('SCPPER_DEBUG')) {
         $profiler = new \Zend\Db\Adapter\Profiler\Profiler();
         $result->setProfiler($profiler);
         if ($result->getPlatform()->getName() === 'MySQL') {
             $result->query('SET SESSION query_cache_type=0;', Adapter::QUERY_MODE_EXECUTE);
         }
     }
     return $result;
 }

作者:emove    项目:sf   
/**
  * @return $this
  */
 public function reset()
 {
     $this['adapter'] = $this->share(function () {
         if (!$this->getConfigDb() instanceof Config) {
             throw new BaseException("DatabaseProvider is not configured");
         }
         try {
             $adapter = new Adapter(array('driver' => $this->getConfigDb()->getDriver(), 'database' => $this->getConfigDb()->getDb(), 'username' => $this->getConfigDb()->getUser(), 'password' => $this->getConfigDb()->getPass(), 'hostname' => $this->getConfigDb()->getHost()));
             if (is_array($this->getConfigDb()->getInitialQueries())) {
                 foreach ($this->getConfigDb()->getInitialQueries() as $query) {
                     $adapter->query($query, array());
                 }
             }
             return $adapter;
         } catch (ExceptionInterface $e) {
             throw new BaseException('Error while connecting to db', 0, $e);
         }
     });
     $this['value_storage'] = $this->share(function () {
         return new ValueStorage($this->getCache());
     });
     $this['db'] = $this->share(function () {
         return new DatabaseProvider($this['adapter']);
     });
     $this['cacheMemory'] = $this->share(function () {
         $cache = new CacheProvider();
         $cache->init($this['cache_config']);
         $cache->connect();
         return $cache;
     });
     $this['cacheSession'] = $this->share(function () {
         return new Session();
     });
     $this['identityMap'] = $this->share(function () {
         return new IdentityMap(new IdentityMapStorage(), new IdentityMapStorage(), new IdentityMapStorage());
     });
     $this['transaction'] = $this->share(function () {
         $transaction = new TransactionAggregator();
         foreach ($this['transaction_engines'] as $engine) {
             $transaction->registerTransactionEngine($engine);
         }
         return $transaction;
     });
     $this['transaction_engines'] = $this->share(function () {
         return [$this->getDb(), $this->getCache()->getAdapter(), $this->getIdentityMap()];
     });
     $this['repository'] = $this->share(function () {
         return new Repository();
     });
     return $this;
 }

作者:khinmyatky    项目:Office_Managemen   
/**
  * Create db adapter service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return Adapter
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $adapter = new Adapter($config['db']);
     $authStorage = $serviceLocator->get('Sundew\\AuthStorage');
     $user = array();
     if (!$authStorage->isEmpty()) {
         $user = $authStorage->read();
     }
     $fileName = 'Query' . date('Ymd') . '.log';
     $logger = new SundewLogger($fileName, $user);
     $adapter->setProfiler($logger);
     return $adapter;
 }

作者:t4we    项目:mai   
private function createTable($query)
 {
     try {
         $this->dbAdapter->query($query, DbAdapter::QUERY_MODE_EXECUTE);
     } catch (\PDOException $e) {
         if (strpos($e->getMessage(), 'table or view already exists') === false) {
             echo $e->getMessage() . PHP_EOL;
             exit(1);
         }
     } catch (\Exception $e) {
         echo $e->getMessage() . PHP_EOL;
         exit(1);
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号