maxxd Posted March 23, 2014 Share Posted March 23, 2014 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! Quote Link to comment https://forums.phpfreaks.com/topic/287210-mysqli-prepared-statement-abstraction-issue/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.