Update

Update existing row(s) within a database table.


update(string $table, array $nvp)

Always apply filters with a where clause to ensure the update query only target specific row(s) and not the entire table.


where(array $filters)

Arguments

$table: string

Define a database table name to insert data into.

$nvp: array

A name-value-pair array containing the column and its value to be updated.


$nvp = [
    'column1' => 'the value of column1',
    'column2' => 'the value of column2',
    // Numeric value is allowed
    'column3' => 10
];

Sample Usage


// This is a simple UPDATE example
try{
	// Update an existing user from the users table.
	// We're going to change the first name from "Joe" to "Joseph"
	$s = $squibble->update('users', [
		'first_name'	=> 'Joseph'
	])->where([
		'id[=]' => 104
	]);
	// Execute the update query
	$updated = $s->execute();
}catch(PDOException $e){
	echo "Error, {$e->getCode()}, {$e->getMessage()}";
}catch(Exception $e){
	echo "Error, {$e->getCode()}, {$e->getMessage()}";
}

Facebook
Twitter
LinkedIn