I'm trying to make an insert using pdo and dao, I have little knowledge in case, I made it on top of a template that works fine, but when I do with more fields and another bank the code does not give error but returns nothing and do not insert.
public function insert() {
$sql = new Sql();
$results = $sql->select("CALL sp_clientes_insert(:NOME, :EMAIL, :SENHA, :TELEFONE, :ENDERECO, :CPF, :COMPLEMENTO, :NUMERO, :BAIRRO, :CIDADE, :ESTADO, :CEP)" ,
array(
':NOME'=>$this->getNome(),
':EMAIL'=>$this->getEmail(),
':SENHA'=>$this->getSenha(),
':TELEFONE'=>$this->getTelefone(),
':ENDERECO'=>$this->getEndereco(),
':CPF'=>$this->getCpf(),
':COMPLEMENTO'=>$this->getComplemento(),
':NUMERO'=>$this->getNumero(),
':BAIRRO'=>$this->getBairro(),
':CIDADE'=>$this->getCidade(),
':ESTADO'=>$this->getEstado(),
':CEP'=>$this->getCep()
));
if (count($results) > 0){
$this->setData($results[0]);
}
}
<?php
class Sql extends PDO {
private $conn;
private $dbHost = "localhost";
private $dbUsername = "root";
private $dbPassword = "";
private $dbName = "banco_bd";
public function __construct() {
$this->conn = new PDO("mysql:host=" . $this->dbHost . ";dbname=" . $this->dbName . ";charset=utf8", $this->dbUsername, $this->dbPassword);
}
private function setParams($statement, $parameters = array()) {
foreach ($parameters as $key => $value) {
$this->setParam($statement, $key , $value);
}
}
private function setParam($statement, $key, $value) {
$statement->bindParam($key, $value);
}
public function query($rawQuery, $params = array()) {
$stmt = $this->conn->prepare($rawQuery);
$this->setParams($stmt, $params);
$stmt->execute();
return $stmt;
}
public function select($rawQuery, $params = array()):array
{
$stmt = $this->query($rawQuery, $params);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
?>
PROCEDURE
CREATE DEFINER='usuario'@'%' PROCEDURE 'sp_clientes_insert'(
pnome varchar(255),
pemail varchar(255),
psenha varchar(255),
ptelefone varchar(255),
pendereco varchar(255),
pcpf varchar(14),
pnumero varchar(50),
pcomplemento varchar(100),
pbairro varchar(255),
pcidade varchar(255),
pestado varchar(2),
pcep varchar(8)
)
BEGIN
INSERT INTO clientes (nome, email, senha, telefone, endereco, cpf, numero, complemento, bairro, cidade, estado, cep, notas)
values (pnome, pemail, psenha, ptelefone, pendereco, pcpf, pnumero, pcomplemento, pbairro, pcidade, pestado, pcep, pnotas);
SELECT * FROM clientes WHERE id = LAST_INSERT_ID();
END