Skip to content

Latest commit

 

History

History
236 lines (165 loc) · 2.92 KB

update.md

File metadata and controls

236 lines (165 loc) · 2.92 KB

PHP Database

Go back

UPDATE

$stmt = $connection->update();
// UPDATE ...

top

SQLServer only.

$stmt->top(10);
// UPDATE TOP (10) ...
$stmt->top(10)->percent();
// UPDATE TOP (10) PERCENT ...

table

$stmt->table('t1');
// UPDATE t1
$stmt->table('t1', 't2');
// UPDATE t1, t2
$stmt->table(['a' => 't1', 'b' => 't2']);
// UPDATE t1 a, t2 b

See Subquery.

$stmt->table(
    $connection->select()
    ->columns('c1')
    ->from('t1')
);
// UPDATE (SELECT c1 FROM t1)

See Table.

use MichaelRushton\Database\SQL\Components\Table;

$stmt->table(new Table('t1'));
// UPDATE t1

set

$stmt->set('c1', $param);
// UPDATE ... SET c1 = ?
$stmt->set([
    'c1' => $param1,
    'c2' => $param2,
]);
// UPDATE ... SET c1 = ?, c2 = ?

join

See join.

$stmt->join('t2');
// UPDATE ... JOIN t2

where

See where.

$stmt->where('c1', $param);
// UPDATE ... WHERE c1 = ?

whereCurrentOf

PostgreSQL and SQLServer only.

$stmt->whereCurrentOf('cursor');
// UPDATE ... WHERE CURRENT OF cursor

orderBy

MariaDB, MySQL and SQLite only.

See order by.

$stmt->orderBy('c1');
// UPDATE ... ORDER BY c1

limit

MariaDB, MySQL, and SQLite only.

See limit.

$stmt->limit(10);
// UPDATE ... LIMIT 10

with

See with.

use MichaelRushton\Database\SQL\Components\CTE;

$stmt->cte(
    'cte1',
    function ($select)
    {
        $select->from('t1');
    },
    function (CTE $cte)
    {

    }
);
// WITH cte1 AS (SELECT * t1) UPDATE ...

lowPriority

MariaDB and MySQL only.

$stmt->lowPriority();
// UPDATE LOW_PRIORITY ...

ignore

MariaDB and MySQL only.

$stmt->ignore();
// UPDATE IGNORE ...

orFail

SQLite only.

$stmt->orFail();
// UPDATE OR FAIL ...

orIgnore

SQLite only.

$stmt->orIgnore();
// UPDATE OR IGNORE ...

orReplace

SQLite only.

$stmt->orReplace();
// UPDATE OR REPLACE ...

orRollBack

SQLite only.

$stmt->orRollBack();
// UPDATE OR ROLLBACK ...

from

PostgreSQL, SQLite, and SQLServer only.

See from.

$stmt->from('t1');
// UPDATE ... FROM t1

returning

See returning.

MariaDB, PostgreSQL and SQLite only.

$stmt->returning();
// UPDATE ... RETURNING *

output

SQLServer only.

$stmt->output('INSERTED.c1', 'DELETED.c1');
// UPDATE ... OUTPUT INSERTED.c1, DELETED.c1 ...
$stmt->output(['a' => 'INSERTED.c1', 'b' => 'DELETED.c1']);
// UPDATE ... OUTPUT INSERTED.c1 a, DELETED.c1 b ...