Can not pass parameter 2 by reference using PDO like

1

I am doing a search in the DB where the parameters are passed and I use LIKE to search, but the search returns me the error PHP Fatal error: Can not 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 error on the server points to the line with the field '%'. $ this-> inputSearchProtocol. '%'

    
asked by anonymous 27.10.2018 / 20:07

1 answer

3

The bindParam() gets the parameters by reference, so you can not use literals, just 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.'%');


Manual:

  

link

  

link

  

link

    
27.10.2018 / 20:11