3
When trying to perform an INSERT in my table with PDO, I get the following error: SQLSTATE[23000]: Integrity Constraint Violation: 1062 Duplicate entry '0' for key 'PRIMARY'
I’ve researched enough and seen some similar problems, but all for lack of AUTO_INCREMENT in the table, however. My chart has AUTO_INCREMENT and is with the right PRIMARY-KEY. I even made an INSERT in the hand in the same way that is being done in the code and the INSERT worked.
Follows the codes:
Table query:
CREATE TABLE usuarios (
usua_id INT NOT NULL AUTO_INCREMENT,
usua_email VARCHAR(200) NOT NULL,
usua_password VARCHAR(250) NOT NULL,
usua_status ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
data_create TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
data_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(usua_id),
UNIQUE (usua_email)
);
Excerpt from php code that makes the Insert:
//INSERT
$query = "INSERT INTO usuarios (usua_email, usua_password) VALUES (:usua_email, :usua_password)";
$conexao = Database::getInstance()->prepare($query);
$conexao->bindValue(":usua_email", $this->getUsuaEmail());
$conexao->bindValue(":usua_password", md5($this->getUsuaPassword()));
//Debug::dump($conexao->queryString);
$conexao->execute();
Query successfully rescaled at hand:
MariaDB [memorando]> insert into usuarios (usua_email, usua_password) values ('[email protected]','??????');
Query OK, 1 row affected (0.05 sec)
It is with php that gives error?
– Miguel