I had an issue where I executed a stored procedure with variables:
INSERT INTO table_walkinleads
VALUES('', FirstName, LastName, Phone, Email, NOW())
but although this was working perfectly in phpmyadmin. It was not the case in my php code.
And the MAIN reason was because of this.
foreach($params as $name => $value ) {
$this->query->bindParam($name,$value);
}
Look carefully at the $value
variable in the foreach statement. Before was like that. But after some investigation, I come to realize it needed to be &$value
. But WHY? What is the difference? Why just adding that reference in the value variable makes the difference in making my stored procedure work correctly?
foreach($params as $name => &$value ) {
$this->query->bindParam($name,$value);
}
PS: the error was still executing the stored procedure, BUT the last variable was inserted as the same value for ALL the variables in the stored procedure. Making it look like I just entered the SAME variable for all the stored procedure variables.
Does anyone have an explanation for this behavior and the reason behind it?