Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Model create bug

Model create() two times like this:

$model->create(array('name' => 'Han', 'year' => '1989')); $model->create(array('name' => 'Zhang', 'year' => '1996'));

It occurred an error:"Record cannot be created because it already exists"



7.2k

May be your tables has unique key. Check this.

CREATE TABLE IF NOT EXISTS mytable ( id int(10) NOT NULL AUTO_INCREMENT, name varchar(70) NOT NULL, year int(11) NOT NULL, PRIMARY KEY (id) );

You can attach a logger to the database connections to see what SQL statements are being executed by the ORM: https://docs.phalconphp.com/en/latest/reference/db.html#logging-sql-statements



2.2k
Accepted
answer

Use $connection->insert()