PHP: Hypertext Preprocessor (original) (raw)
`stmt_init() seems to clear previous (possibly erroneous) results on the DB connection, which means you don't necessarily need to use it but it could make the code more robust.
In a PHPUnit test, I had a sequence of prepared queries on the same connection. One of them fetched a row from a SELECT but didn't keep fetching until it drained the connection, so it left some stale results. When the next query did this:
db=db = db=this->getConnection()->getDbConnection(); preparedQuery=preparedQuery = preparedQuery=db->prepare ($query); ?>the prepare() call generated an error: "Could not prepare query: Commands out of sync; you can't run this command now." Changing to this:
db=db = db=this->getConnection()->getDbConnection(); preparedQuery=preparedQuery = preparedQuery=db->stmt_init(); preparedQuery−>prepare(preparedQuery->prepare (preparedQuery−>prepare(query); ?>resolved the problem.
`