Cannot pass Parameter 2 by Reference using PDO like

Asked

Viewed 290 times

1

I’m doing a search in the BD where the parameters are passed and use LIKE to search, only the search returns me the error PHP Fatal error: Cannot pass Parameter 2 by Reference

$this->Query = $this->Conn->prepare('select * '.
                                    'from tabela '.
                                    'inner join tabela2 on tabela.pr_status = prstatus.prstatus_status '.
                                    'where :tableColumn like :inputSearchProtocol'
                                    );  
$this->Query->bindParam(':tableColumn'          ,$this->tableColumn);
$this->Query->bindParam(':inputSearchProtocol'  ,'%'.$this->inputSearchProtocol.'%');

The server error points to the line with the field '%'. $this->inputSearchProtocol.'%'

1 answer

4


The bindParam() receives the parameters by reference, so you can not use literals, only variables.

Using variable, it looks like this:

$variavel = '%'.$this->inputSearchProtocol.'%';
$this->Query->bindParam(':inputSearchProtocol', $variavel);

But it’s probably much simpler to use bindValue:

$this->Query->bindValue(':inputSearchProtocol'  ,'%'.$this->inputSearchProtocol.'%');


Handbook:

https://secure.php.net/manual/en/pdostatement.bindparam.php

https://secure.php.net/manual/en/pdostatement.bindvalue.php

https://secure.php.net/manual/en/language.references.pass.php

Browser other questions tagged

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