Horde_Db_Adapter::selectAssoc PHP Method

selectAssoc() public method

selectAssoc("SELECT id, name FROM companies LIMIT 3") => [1 => 'Ford', 2 => 'GM', 3 => 'Chrysler']
public selectAssoc ( string $sql, mixed $arg1 = null, string $arg2 = null ) : array
$sql string SQL statement.
$arg1 mixed Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
return array
    public function selectAssoc($sql, $arg1 = null, $arg2 = null);

Usage Example

Ejemplo n.º 1
0
 /**
  * Check for object existence without causing the objects to be created.
  * Helps save queries for things like tags when we already know the object
  * doesn't yet exist in rampage tables.
  *
  * @param mixed string|array $objects  Either an object identifier or an
  *                                     array of them.
  * @param mixed $type                  A type identifier. Either a string
  *                                     type name or the integer type_id.
  *
  * @return mixed  Either a hash of object_id => object_names or false if
  *                the object(s) do not exist.
  * @throws InvalidArgumentException, Content_Exception
  */
 public function exists($objects, $type)
 {
     $type = current($this->_typeManager->ensureTypes($type));
     if (!is_array($objects)) {
         $objects = array($objects);
     }
     if (!count($objects)) {
         return array();
     }
     // Ensure we take the object as a string indentifier.
     foreach ($objects as &$object) {
         $object = strval($object);
     }
     $params = $objects;
     $params[] = $type;
     try {
         $ids = $this->_db->selectAssoc('SELECT object_id, object_name FROM ' . $this->_t('objects') . ' WHERE object_name IN (' . str_repeat('?,', count($objects) - 1) . '?)' . ' AND type_id = ?', $params);
         if ($ids) {
             return $ids;
         }
     } catch (Horde_Db_Exception $e) {
         throw new Content_Exception($e);
     }
     return false;
 }
All Usage Examples Of Horde_Db_Adapter::selectAssoc