When I try to INSERT my table with PDO, I get the following error: SQLSTATE [23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'
I've done a lot of research and saw some similar problems, but all for lack of AUTO_INCREMENT in the table, however. My table has AUTO_INCREMENT and is with PRIMARY-KEY right. I made up an INSERT in the hand in the same way it is done in the code and INSERT worked.
Follow 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 of the 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 radiated successfully in the hand:
MariaDB [memorando]> insert into usuarios (usua_email, usua_password) values ('[email protected]','??????');
Query OK, 1 row affected (0.05 sec)