Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7937 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80073 invoked by uid 1010); 17 Feb 2004 21:46:15 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 80017 invoked from network); 17 Feb 2004 21:46:15 -0000 Received: from unknown (HELO miranda.org) (209.58.150.153) by pb1.pair.com with SMTP; 17 Feb 2004 21:46:15 -0000 Received: (qmail 12041 invoked by uid 546); 17 Feb 2004 21:46:15 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 17 Feb 2004 21:46:15 -0000 Date: Tue, 17 Feb 2004 16:46:15 -0500 (EST) X-X-Sender: adam@miranda.org To: internals@lists.php.net Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: mysqli_fetch() return values From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) I would like to propose a change in how mysqli_fetch() signifies "no more data." It should return NULL instead of MYSQLI_NO_DATA (a positive value) because it leads to cleaner PHP code and is more consistent with other MySQL fetch functions. Currently, mysqli_fetch() returns one of three different values: Value | Meaning --------------------------------- true | Successful Fetch false | Error MYSQLI_NO_DATA | No more data --------------------------------- Returning the constant MYSQLI_NO_DATA (100) mimics the underlying MySQL C API, but it leads to non-natural PHP Code: while (MYSQLI_NO_DATA !== mysqli_fetch($db)) { // do something. } Every other MySQL function allows you to do: while ($row = mysqli_fetch_row($db)) { // do something. } And I think it'd be much nicer to allow people to write: while (mysqli_fetch($db)) { // do something. } Therefore, I propose that instead of returning MYSQLI_NO_DATA, we return NULL. Here's my reasoning: 1) The other mysqli_fetch_* functions now return NULL in this situation. 2) We're already modifying the MySQL C-level return values. In C, mysql_fetch() returns 0 on success and 1 upon an error. We've swapped these values to behave more PHP-like. 3) When 0 signifies success, a positive "no more data" error code makes sense because it looks (logically) like an error inside a while. That doesn't hold true now that we've flipped these values. -adam -- adam@trachtenberg.com author of o'reilly's php cookbook avoid the holiday rush, buy your copy today!