I get datetime from this way:
class DB_Functions extends DB_Connect{
private $dbConnect = "";
public $dtime;
public function __construct() {
$this->dbConnect = $this->pdo_connect();
$this->dtime = new DateTime();
}
public function destruct() {
$this->dbConnect = null;
}
public function exampleInsert() {
.
.
.
$result->bindParam(':dateCreation',$this->dtime->format("Y-m-d H:i:s"),PDO::PARAM_STR);
}
}
Then when I use dtime to insert in a table, like this:
Line 1708: $result->bindParam(':dateCreation',$this->dtime->format("Y-m-d H:i:s"),PDO::PARAM_STR);
Display this error:
<b>Strict Standards</b>: Only variables should be passed by reference in <b>include\DB_Functions.php</b> on line <b>1708</b><br />
My declaration to get datetime is wrong?
The problem is that you are using
bindParam()which actually binds a variable to the parameter in the query. This must be a variable, not a method call that returns a value.This allows for usage like:
In your case you might want to use
bindValue(). Which actually binds the value to the parameter in an immutable fashion. Either that or store your formatted datetime into a different class variable and continue to usebindParam()with that new variable.