note 60589 deleted from function.mysqli-free-result by hholzgra

From: Date: Sat, 29 Sep 2007 10:55:58 +0000
Subject: note 60589 deleted from function.mysqli-free-result by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130919@lists.php.net to get a copy of this message
Note Submitter: jon at fuck dot org ---- better to wrap the result object in its own class, separate from the connection object wrapper: __destruct() can be used to automatically free the result set. this isn't a terribly new design pattern, either. just be sure to destroy your result object before you make another query with the same DBI instance if you happen to change the flag to MYSQLI_USE_RESULT. actually, you'll find if you write the code with or without a wrapper class that it looks rather the same. this code also allows you to track what kind of result set you've created by passing the flag around, although i don't think i'd ever need to use that myself. class DBI { function __construct() { $this->dbconn = new mysqli(...); } function query($sql, $flag = MYSQLI_STORE_RESULT) { $result = $this->dbconn->query($sql, $flag); return new RecordSet($result, $flag); } }; class RecordSet { function __construct($res, $flag = MYSQLI_STORE_RESULT) { $this->result = $res; $this->flag = $flag; } function __destruct() { $this->result->free(); } };

« previous php.notes (#130919) next »