ds111 Posted August 5, 2009 Share Posted August 5, 2009 Hello I have the following code.. <?php $mysqli = db_connect ($dbn); // <-- This returns mysqli dbconnection link $query = "SELECT user_id, role, test FROM users WHERE uid=? AND id=?"; $stmt = $mysqli->stmt_init (); if ($stmt->prepare ($query)) { $stmt->bind_param ("ii", $uid, $id); $stmt->execute (); $stmt->bind_result ($this->user_id, $this->role, $this->test); $stmt->fetch (); $stmt->close (); $mysqli->close (); return NULL; } I am using MYSQLi as you can see. I have a question: Is $mysqli->close() the same as $stmt->close() ? Do I need those two lines of code or by closing $stmt I also close $mysqli since its in the same class? Thank you for any answers. Link to comment https://forums.phpfreaks.com/topic/168981-stmtclose-vs-mysqliclose/ Share on other sites More sharing options...
ds111 Posted August 5, 2009 Author Share Posted August 5, 2009 Anyone Know? Link to comment https://forums.phpfreaks.com/topic/168981-stmtclose-vs-mysqliclose/#findComment-891747 Share on other sites More sharing options...
ldougherty Posted August 5, 2009 Share Posted August 5, 2009 http://php.oregonstate.edu/manual/en/mysqli.close.php mysqli::close Closes a previously opened database connection. http://us.php.net/manual/en/mysqli-stmt.close.php mysqli_stmt::close Closes a prepared statement. Link to comment https://forums.phpfreaks.com/topic/168981-stmtclose-vs-mysqliclose/#findComment-891759 Share on other sites More sharing options...
ds111 Posted August 6, 2009 Author Share Posted August 6, 2009 Does this work when you are instantiating the Mysqli class as well? because it looks like you call mysqli_stmt_close() only when you do not use the OOP style. Since $stmt is a "shortcut" to $mysqli->stmt_init(); then wouldn't $stmt->close() be the same thing as: $mysqli->stmt_init()->close(); ? What does stmt_init() return? I thought it returns $this so that you can then call another function of the Mysqli class...? Link to comment https://forums.phpfreaks.com/topic/168981-stmtclose-vs-mysqliclose/#findComment-892315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.