note 60589 added to function.mysqli-free-result

From: Date: Wed, 11 Jan 2006 18:39:26 +0000
Subject: note 60589 added to function.mysqli-free-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-101579@lists.php.net to get a copy of this message
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(); } }; ---- Manual Page -- http://www.php.net/manual/en/function.mysqli-free-result.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60589 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60589&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60589&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101579) next »