php - mysqli prepeare on array? -


i writing own library querying database , want encapsulate mysqli_prepeare() , mysqli_bind methods, want write generic method dynamic number of parameters. mean can pass example:

array("is", $integerid, $stringname).  

the solution have found is:

function prepeare($notescapedsql, $attrs) {     $query = mysqli_prepare($this->dbconn, $notescapedsql);      $ref = new reflectionclass('mysqli_stmt');      $method = $ref->getmethod("bind_param");      $method->invokeargs($query,$attrs);   } 

but not working me, did not spent time on debuging because not elegant way of solving problem since uses reflection not supported on earlier versions of php. there sollutions or suggestions?

i don't know why use reflection class , why didn't use $query returns mysqli_stmt object.

moreover, invokeargs call_user_func_array take array second parameter. so, best use typehint array on second parameter in function prepeare.

you can use call_user_func_array:

function prepeare($notescapedsql, array $attrs) {     $mysqli_stmt = mysqli_prepare($this->dbconn, $notescapedsql);     call_user_func_array(array($mysqli_stmt, "bind_param"), $attrs);     return $mysqli_stmt; } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -