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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.