Error when using bindParam: Only variables should be passed by reference

2

I'm getting an error when I use the PDP bindParam , code:

ConnectionPDO Class:

function __construct($dsn, $username = NULL, $password = NULL, $options = NULL) {
  parent::__construct($dsn, $username, $password, $options);
  $this->LoadDriverMethods();
}

public function insert($table, $data) {
  $this->lastSQL = $this->driver->insert($table, $data);

  $stmt = $this->prepare($this->lastSQL);

  $this->driver->setParams($this->stmt);

  return $this->stmt;
}

private function LoadDriverMethods(){
  $driver = __DIR__ . DIRECTORY_SEPARATOR . 'drivers' . 
                      DIRECTORY_SEPARATOR . 'sqldriver.' . 
                      strtolower($this->getAttribute(PDO::ATTR_DRIVER_NAME)) . '.php';

  if (!is_file($driver))
     throw new Exception('Não foi possível carregar os métodos do driver', 1);

  require_once $driver;
  $this->driver = new SQLDriver();
}

SQLDriver class:

public function setParams(PDOStatement $stmt){
  $params = $this->getParams();
  if (is_array($params) && !empty($params))
     foreach ($params as $param => $value)
     $stmt->bindParam($param, $this->prepareParam($value), $this->getParamType($value));
}

Error:

  

Strict Standards: Only variables should be passed by reference in \ ConnectionPDO \ drivers \ sqldriver.mysql.php

The following line in the SQLDriver class refers to:

$stmt->bindParam($param, $this->prepareParam($value), $this->getParamType($value));
    
asked by anonymous 22.09.2015 / 23:48

1 answer

3

You can not pass values or method returns to bindParam () because it expects references (variables) in this case just switch to bindValue () .

I see that you are mounting a lib, bindParam() will only make a difference in the use of stored procedures that return value, in that the return of it goes to the specified variable

You can build a dynamic bind with this suggestion

What's the difference between bindParam and bindValue?

    
22.09.2015 / 23:50