martes, 9 de agosto de 2016

Ejecutando querys deinsert y update

\Yii::$app->db ->createCommand('INSERT INTO user (email, password) VALUES
("test3@example.com", "test3");') ->execute();

// INSERT ( tablename, [ attributes => attr ] )
\Yii::$app->db
->createCommand()
->insert('user', [
'email' => 'test4@example.com',
'password' => 'changeme7',
'first_name' => 'Test',
'last_name' => 'User',
'created_at' => time(),
'updated_at' => time()
])
->execute();

// DELETE ( tablename, condition )
\Yii::$app->db
->createCommand()
->delete('user', 'id = 3')



// batchInsert( tablename, [ properties ], [ rows ] )
\Yii::$app->db
->createCommand()
->batchInsert('user', ['email', 'password', 'first_name', 'last_name',
'created_at', 'updated_at'],
[
['james.franklin@example.com', 'changeme7', 'James', 'Franklin',
time(), time()],
['linda.marks@example.com', 'changeme7', 'Linda', 'Marks', time(),
time()]
['roger.martin@example.com', 'changeme7', 'Roger', 'Martin',
time(), time()]
])
->execute();

No hay comentarios:

Publicar un comentario