Pdostatement::execute(): SQLSTATE[HY093]: Invalid Parameter number

Asked

Viewed 589 times

-1

Good evening, Folks.

I’m getting the following error: Pdostatement::execute(): SQLSTATE[HY093]: Invalid Parameter number: number of bound variables does not match number of tokens in C: xampp htdocs ZENVIA php-Rest-api model Connectmysql.php on line 43.

I have already reviewed 200x and I can’t identify... the number of parameters x bind is ok.. Below, part of the code:

    <?php 

class ConnectMysql extends PDO {

    private $conn;


    public function __construct(){

        $this->conn = new PDO(....);

    }


    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);


    }

    public function insert ($data, $params = array()){


            $stmt = $this->select("CALL sp_base_insert(:MTID, :OPERACAO, :STATUS_TRATAMENTO, :ID_MSG, :ESTAGIO_ENVIO, :OS, :PDV, :CLIENTE, :TELEFONE_1, TELEFONE_2, TELEFONE_3, :SERVICE_TYPE);", 
                array(              
                ':MTID'=> $data["mtid"],    
                ':OPERACAO'=> $data["operacao"],
                ':STATUS_TRATAMENTO'=> $data["status_tratamento"],
                ':ID_MSG'=> $data["id_msg"],
                ':ESTAGIO_ENVIO'=> $data["estagio_envio"],
                ':OS'=> $data["os"],
                ':PDV'=> $data["pdv"],
                ':CLIENTE'=> $data["cliente"],
                ':TELEFONE_1'=> $data["telefone_1"],
                ':TELEFONE_2'=> $data["telefone_2"],
                ':TELEFONE_3'=> $data["telefone_3"],
                ':SERVICE_TYPE' => $data["service_type"]
                )
            );
    }
}

?>

The term is as follows::

    DELIMITER $$
CREATE PROCEDURE sp_base_insert(
pmtid varchar(30),
poperacao enum('AUD','AGF','DEV'),
pstatus_tratamento varchar(15), 
pid_msg char(2), 
pestagio_envio enum('1','2','3'), 
pos int(9), 
ppdv varchar(8), 
pcliente int(15), 
ptelefone_1 varchar(13), 
ptelefone_2 varchar(13),
ptelefone_3 varchar(13), 
pservice_type varchar(30)
)
BEGIN

    insert into sms (mtid, operacao, status_tratamento, id_msg, estagio_envio, os, pdv, cliente, telefone_1, telefone_2, telefone_3, service_type) 
    values (pmtid, poperacao, pstatus_tratamento, pid_msg, pestagio_envio, pos, ppdv, pcliente, ptelefone_1, ptelefone_2, ptelefone_3, pservice_type);

END $$
DELIMITER ;

Someone can help me?

1 answer

0


It’s a typo, when the message appears:

number of bound variables does not match number of tokens

It is always related to your query "Binds"

Have two TOKENS with error in CALL:

:TELEFONE_1, TELEFONE_2, TELEFONE_3, :SERVICE_TYPE

Should be:

:TELEFONE_1, :TELEFONE_2, :TELEFONE_3, :SERVICE_TYPE

Fix this and it’ll work.

  • Guilherme, thank you so much!! I can’t believe I didn’t see this kkk... It worked out now!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.