Insert

Insert new data into a database table.


insert(string $table, array $nvp)

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 inserted.


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

Sample Usage


// This is a simple INSERT example
try{
	// Insert a new entry into the database table users.
	$s = $squibble->insert('users', [
		'first_name'	=> 'Joe',
		'last_name'	=> 'Green',
		'email_address'	=> '[email protected]'
	]);
	// Execute the insert query
	$inserted = $s->execute();
}catch(PDOException $e){
	echo "Error, {$e->getCode()}, {$e->getMessage()}";
}catch(Exception $e){
	echo "Error, {$e->getCode()}, {$e->getMessage()}";
}

Facebook
Twitter
LinkedIn