mysql - Problem with multiple prepared statements -


here's issue. have prepared statement, this:

$select_something = $db->stmt_init(); $select_something->prepare (" select whatever  table "); $select_something->execute(); $select_something->bind_result($whatever); 

when alone - works. when add 1 after it's execution works. when try first prepare them both:

$select_something = $db->stmt_init(); $select_something->prepare (" select whatever  table "); 

and execute them later on:

$select_something->execute(); $select_something->bind_result($whatever); 

the first statement gets executed, , second 1 throws error both lines above:

*warning: mysqli_stmt::execute() [mysqli-stmt.execute]: invalid object or resource mysqli_stmt*

note, statements named differently ($select_something , $select_something_else), thought it's needless repeat code.

thanks!

note mysqli extension has been replaced pdo, simpler use , better behaved. should use rather mysqli. if need pdo tutorial, try "writing mysql scripts php , pdo". if switch, may still wish figure out going wrong, in case read on.

that particular error means you're not dealing mysqli_stmt in $select_something or $select_something_else. functions in many extensions (especially db extensions) return false when fail, rather resource or object. that's what's happening here. follow proper error handling procedure testing return value of functions fail. use mysqli::error description of why mysqli function/method failing.

you may running across limitation of mysqli , mysql driver: lower level mysql_use_result() or mysql_store_result() must called on results before can used. default, mysqli_stmt::execute calls mysql_use_result, means old result must closed before new query run (which mentioned in documentation mysqli::query()). proper application of mysqli_stmt::store_result may fix problem.

note shouldn't need call mysqli::stmt_init(), present (as mysqli_stmt_init) support procedural programming. instead, can use mysqli::prepare().


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -