开发者

Can someone help explain how this function works (mysqli prepared statment array function)

i just need a little help on how i could implement this function. i cant quite read this. I found this function to stick the results from a mysqli prepared statement query into an array which is what i am trying to do, but i am unsure how to use the function.

$meta = $statement->result_metadata(); 

while ($field = $meta->fetch_field()) { 
    $params[] = &$row[$field->开发者_如何转开发name]; 
} 

call_user_func_array(array($statement, 'bind_result'), $params);                
while ($statement->fetch()) { 
    foreach($row as $key => $val) { 
        $c[$key] = $val; 
    } 
    $hits[] = $c; 
} 
$statement->close();


while ($field = $meta->fetch_field()) { 
    $params[] = &$row[$field->name]; 
}

This looks at the result set and extracts the field names into an array.

call_user_func_array(array($statement, 'bind_result'), $params);                

That array of field names is then used to auto-create variables of the same name as the field, to which the database results are bound to. This is very bad practice, as it auto-creates variables based on query results, and can potentially overwrite a variable you'd be using for other purposes elsewhere. You'd never know why, because there's no explicit assignment to that variable name to search for.

The while loop is highly inefficient, but retrieves each row from the query results and places them into an array called $hits.

So, basically, it's a gold plated piece of bovine excrement that impressively does very little.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜