Dibi\Connection::query PHP Method

query() final public method

Generates (translates) and executes SQL query.
final public query ( $args ) : Result | integer
return Result | integer result set object (if any)
    public final function query($args)
    {
        $args = func_get_args();
        return $this->nativeQuery($this->translateArgs($args));
    }

Usage Example

Example #1
0
 /**
  * @param $namespace
  * @param $name
  * @param $locale
  * @return string
  * @throws DriverException
  */
 private function findContentAndFillCache($namespace, $name, $locale)
 {
     try {
         /** @var array $result */
         $result = $this->connection->select('*')->from(self::TABLE)->where(['namespace%s' => $namespace])->fetchAll();
     } catch (DriverException $e) {
         // check table not exist
         if ($e->getCode() == 1146) {
             $this->connection->query('
                   CREATE TABLE [' . self::TABLE . '] (
                   [id] int(11) NOT NULL AUTO_INCREMENT,
                   [namespace] varchar(255) NOT NULL,
                   [name] varchar(255) NOT NULL,
                   [locale] varchar(255) NOT NULL,
                   [content] text NOT NULL,
                   PRIMARY KEY ([id]),
                   UNIQUE KEY [uniq_record] ([namespace],[name],[locale])
                 );');
             $result = [];
         } else {
             throw $e;
         }
     }
     $tmp = [];
     foreach ($result as $item) {
         if (!isset($tmp[$item['name']])) {
             $tmp[$item['name']] = [];
         }
         $tmp[$item['namespace']][$item['name']][$item['locale']] = $item['content'];
     }
     $this->saveCachedNamespace($namespace, $tmp);
     return isset($tmp[$namespace][$name][$locale]) ? $tmp[$namespace][$name][$locale] : '';
 }
All Usage Examples Of Dibi\Connection::query