Jump to content

Stmt::close vs Mysqli::close


ds111

Recommended Posts

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

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...?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.