Horde_Db_Adapter::insert PHP Method

insert() public method

Inserts a row into a table.
public insert ( string $sql, array | string $arg1 = null, string $arg2 = null, string $pk = null, integer $idValue = null, string $sequenceName = null ) : integer
$sql string SQL statement.
$arg1 array | string Either an array of bound parameters or a query name.
$arg2 string If $arg1 contains bound parameters, the query name.
$pk string The primary key column.
$idValue integer The primary key value. This parameter is required if the primary key is inserted manually.
$sequenceName string The sequence name.
return integer Last inserted ID.
    public function insert($sql, $arg1 = null, $arg2 = null, $pk = null, $idValue = null, $sequenceName = null);

Usage Example

Ejemplo n.º 1
0
 /**
  * Ensure that an array of types exist in storage. Create any that don't,
  * return type_ids for all.
  *
  * @param mixed $types  An array of types or single type value. Values typed
  *                      as an integer are assumed to already be an type_id.
  *
  * @return array  An array of type_ids.
  * @throws Content_Exception
  */
 public function ensureTypes($types)
 {
     if (!is_array($types)) {
         $types = array($types);
     }
     $typeIds = array();
     $typeName = array();
     // Anything already typed as an integer is assumed to be a type id.
     foreach ($types as $typeIndex => $type) {
         if (is_int($type)) {
             $typeIds[$typeIndex] = $type;
         } else {
             $typeName[$type] = $typeIndex;
         }
     }
     try {
         // Get the ids for any types that already exist.
         if (count($typeName)) {
             $rows = $this->_db->selectAssoc('SELECT type_id, type_name FROM ' . $this->_t('types') . ' WHERE type_name IN (' . implode(',', array_map(array($this->_db, 'quoteString'), array_keys($typeName))) . ')');
             foreach ($rows as $id => $type) {
                 $typeIndex = $typeName[$type];
                 unset($typeName[$type]);
                 $typeIds[$typeIndex] = (int) $id;
             }
         }
         // Create any types that didn't already exist
         foreach ($typeName as $type => $typeIndex) {
             $typeIds[$typeIndex] = intval($this->_db->insert('INSERT INTO ' . $this->_t('types') . ' (type_name) VALUES (' . $this->_db->quoteString($type) . ')'));
         }
     } catch (Horde_Db_Exception $e) {
         throw new Content_Exception($e);
     }
     return $typeIds;
 }
All Usage Examples Of Horde_Db_Adapter::insert