I've run into an issue and getting this to work correctly is melting my brain. I'm wondering if anyone out there can point me in the right direction.
Basically, I'm using a multi threaded message queue handler to insert message values into a database. Everything works correctly, even the code below, but only on the initial insert. After the variables have been binded they keep the the same value, and will not reference the change in the $json object. I've tried several difference ways but I can't seem to get references to work. Any help would be appreciated!
private function handle_insert($message) {
// declare data
$json = json_decode($message->body);
// prepare the statement
if (!isset($this->statement)) $this->prepare_statement();
// if there are no bindings
if (!$this->binding) {
// extract params
extract(get_object_vars($json), EXTR_REFS);
// loop over data
foreach ($json as $key => $value) {
// bind data
$this->statement->bindParam(":{$key}", $$key, $this->pdo_param($$key)); // using function for defined types
}
// params are bound
$this->binding = true;
}
// execute the statement
$this->statement->execute();
}
I could bindParam on every insert, or even use bindValue. However, isn't the point of bindParam to only bind once and then change the value, reducing the need to loop?