Re: call_user_func_array and bind_result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 16, 2011, at 4:51 PM, David Harkness wrote:

> Each *value* in the array must be a reference to an existing variable--they cannot be null or direct values. 

[snip]

Thank you very much for your explanation and example code.  I was missing the fact that the *values* in the array must be references.  I was thinking that call_user_func_array wanted a reference to the array itself where I wanted the values stored, but when I tried doing 

call_user_func_array(array($ps, 'bind_result'), &$params);

I got the following deprecation notice so I knew I was on the wrong track but didn't know where I was going wrong:
Warning: Call-time pass-by-reference has been deprecated in /Applications/apache/htdocs/hila/includes/class.AbstractModel.php on line 176

In the course of studying your example and trying to get it to work I also discovered a problem elsewhere in my code where the value of the primary key field in my MySQL database, defined as 

`user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT

was being returned to PHP as a string instead of an int, and this was causing a type mismatch that ultimately resulted in all fields of the results array being populated with NULLs, which is why all of the examples on the pages I Googled did not appear to be working for me.  

In the end I changed the relevant part of my code to the following and thanks to your help it is now working:

$params = array();
$values = array();
foreach ($metadata as $object) {
	$params[] = &$values[$object->orgname];
}
call_user_func_array(array($ps, 'bind_result'), $params);
$ps->fetch();
   
print "<pre>";
var_dump($values);
print "</pre>";

Thanks again and happy holidays!

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux