Jump to content

mysqli prepared statement abstraction issue


maxxd

Recommended Posts

Hey y'all. I'm having (I think) a senior moment here with something I'm working on. I've got a small database abstraction class that I've written, and I'm trying to do as little work as possible to extend it a bit. Basically, I don't want to have to do a simple deferral method to go from my client code to the mysqli instance, but I also want some control over some of the mysqli functionality. So I'm attempting to implement a __call() magic method that'll pass the method through to the internal mysqli instance. Here's the method:

class myDBAbstraction{
 
/*    other stuff....    */
 
    public function __call($method, $args){
        if(method_exists($this->_conn,$method)){
            $tmp = $this->_conn->$method($args);
            if($tmp === false){
                die("<p>Error {$this->_conn->errno}: {$this->_conn->error}</p>");
            }
            return $tmp;
        }
        $this->error = "Bad call: {$method}";
        return false;
    }
}

Note that $this->_conn is a mysqli() instance stored as a private class property.

The call is simple:

class myClientTester{
 
/*    I instantiate a myDBAbstraction() instance as $this->_conn for this class. I'm very original with naming conventions...    */

    public function testing(){
        if($this->_conn->prepare('UPDATE tbl_copy
                              SET     cpy = ?
                                     ,last_edited = UTC_TIMESTAMP()
                                     ,last_edited_by = ?
                              WHERE pg = ?')){
            $this->_conn->close();
            die("<p>Statement prepared</p>");
        }else{
            die("<p>Error: {$this->_conn->error}</p>");
        }
    }
}

I'm literally just trying to get so far as to prepare the statement - I'll work on the rest later. However, the call to mysqli::prepare() fails. It returns false but myDBAbstraction::$_conn->errno = 0 and myDBAbstraction::$_conn->error is null.

 

Anyone have any ideas as to what I'm doing wrong here?

 

Much thanks in advance for any ideas or advice!

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.