db::insert PHP Method

insert() static public method

Runs a INSERT query
static public insert ( string $table, mixed $input, boolean $ignore = false ) : mixed
$table string The table name
$input mixed Either a key/value array or a valid MySQL insert string
$ignore boolean Set this to true to ignore duplicates
return mixed The last inserted id if everything went fine or an error response.
    static function insert($table, $input, $ignore = false)
    {
        $ignore = $ignore ? ' IGNORE' : '';
        return self::execute('INSERT' . $ignore . ' INTO ' . self::prefix($table) . ' SET ' . self::values($input));
    }

Usage Example

Example #1
0
 public function create($values)
 {
     $values['parent'] = (int) $values['parent'];
     $position = (int) db::select('max(position)')->from(':table:')->where('parent = %i', $values['parent'])->fetchSingle();
     $values['position'] = $position + 1;
     db::insert(':table:', $values)->execute();
     return array('id' => db::getInsertId(), 'title' => $values['title'], 'parent_id' => $values['parent'], 'position' => $values['position']);
 }
All Usage Examples Of db::insert