php - Commands out of sync; you can't run this command now on $mysqli->prepare -
i have php function called getnumrows
:
function getnumrows() { $query = $this->mysqli->prepare("call getnumrows('$this->tablename')") or die('unable prepare: ' . $this->mysqli->error); $query->execute(); $query->store_result(); $query->bind_result($rowcount); while ($query->fetch()) { $numrows = $rowcount; } $query->close(); return $numrows; }
which uses stored procedure call getnumrows('tablename')
:
drop procedure gpstrack.getnumrows; create definer=`******`@`localhost` procedure `getnumrows`( in tab_name varchar( 40 ) ) begin set @t1 = concat( 'select count(*) ', tab_name) ; prepare stmt3 @t1 ; execute stmt3; deallocate prepare stmt3; end;
but fails on row #1 of function with:
unable prepare: commands out of sync; can't run command now
how can use procedure number of rows of table?
i able fix using php:
function getnumrows() { $query = $this->mysqli->prepare("call getnumrows('$this->tablename')") or die('unable prepare: ' . $this->mysqli->error); $query->execute(); $query->store_result(); $query->bind_result($rowcount); $query->fetch(); $numrows = $rowcount; $this->mysqli->next_result();// added line $query->close(); return $numrows; }
Comments
Post a Comment