# MySQLi: bind\_param and objects

**URL:** <https://forums.percona.com/t/mysqli-bind-param-and-objects/232>\
**Category:** Other MySQL® Questions\
**Created:** [March 8, 2007, 3:42am UTC](https://forums.percona.com/t/mysqli-bind-param-and-objects/232 "2007-03-08T03:42:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Himalian](https://avatars.discourse-cdn.com/v4/letter/h/2acd7d/32.png) [@Himalian](https://forums.percona.com/u/Himalian)\
**Post date:** [March 8, 2007, 3:42am UTC](https://forums.percona.com/t/mysqli-bind-param-and-objects/232/1 "2007-03-08T03:42:46Z")

</div>

Hi,

I want to use MySQLi with prepared statements so I’ve prepared the query with the DB object:

$update = $db-\>prepare(“UPDATE bla SET xx=?, yy=? WHERE zz=?”);

Because my application is fully OOP, I have objects with the data I want to use for the query.

class BlaData {var $x;var $y;var $z}$data = array(Lots of BlaData objects);

Now I want to execute the update query for every object in the array.

foreach(…) {$update-\>…???$update-\>Execute();}

How can I now bind the BlaData-\>x, y and z vars to the query without using local variables in bind\_param? All samples of bind\_param work so:

$stmt-\>bind\_param(“ii”,$var1,$var2);foreach() { $var1 = rand(); $stmt-\>execute();}

I tried:

$fd = new BlaData(); //empty$stmt-\>bind\_param(“ii”,$fd-\>x,$fd-\>y);for($i… count($data)… $i++) { $fd = $data[$i] $stmt-\>execute();}

But it doesn’t work, it looks like bind\_param uses the (empty) object I’ve used to first time on every execute() again.

I think that’s because bind\_param stores a reference to the variable which doesn’t change to a new value if I reassign the $fd object.

Is there a way to use the object properties without copying everything from the object to a local variable first? Or is it possible to call bind\_params(); every time in the loop before -\>Execute() or will this affect the performance negatively?  
If bind\_params causes a round trip to the MySQL Server, calling it every time before Execute() is not really an option.

Thanks and best regards,

Himalian
