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

Asked

Viewed 3,509 times

5

I’m getting an error when I use the bindParam from the PDO, 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

Which refers to the following line in class Sqldriver:

$stmt->bindParam($param, $this->prepareParam($value), $this->getParamType($value));

1 answer

5


  • Thanks, I just noticed that the problem was in the method bindParam (the second parameter is a reference), had changed the function $this->prepareParam($value) by a variable, but bindValue worked well. : D

  • @Kaduamaral, is building a framework?

  • Yes rray. Why?

  • @Kaduamaral organized the code :D

  • Is this some ironic joke? : v kkkk... Here the link.

  • No, the code is legal.

  • saved my life :), did not know that term

Show 2 more comments

Browser other questions tagged

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