Store_result and get_result for statement

2019-02-22 19:49发布

问题:

When I use statements in PHP with mysqli library, before I fetch and bind_results I call the store_result. After I've seen the mysqli_result class with methods like fetchArray/object etc. So if I want use it, I call from mysqli_stmt object the method get_results... but if I call before the method store_result it give me an error of "non object" (get_result return false). Es:

$s = $stmt->get_result(); //this work

but if I do

$stmt->store_result();
$s = $stmt->get_result(); //this not work, return false

So I'm trying to understand when I need to user store_result or get_result (and what is the right way) but in Mysql and php doc I didn't find nothing of useful.

PS: Can you explain why I should use the first or the second?

回答1:

Use get_result whenever possible and store_result elsewhere.



标签: php mysql mysqli