Skip to content

Commit

Permalink
Update user guide to better explain use of result mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
sclubricants committed Jun 16, 2021
1 parent a5e9181 commit 9453c7c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions user_guide_src/source/database/results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,25 @@ it returns the current row and moves the internal data pointer ahead.
echo $row->body;
}

For use with MySQLi you must set MySQLi's result mode to
``MYSQLI_USE_RESULT``.
For use with MySQLi you may set MySQLi's result mode to
``MYSQLI_USE_RESULT`` for maximum memory savings. Use of this is not
generally recommended but it can be beneficial in some circumstances
such as writing large queries to csv. If you change the result mode
be aware of the tradeoffs associated with it.

::

$db->resultMode = MYSQLI_USE_RESULT; // for unbuffered results

$query = $db->query("YOUR QUERY");

while ($row = $query->getUnbufferedRow())
{
echo $row->title;
echo $row->name;
echo $row->body;
$file = new \CodeIgniter\Files\File(WRITEPATH.'data.csv');

$csv = $file->openFile('w');

while ($row = $query->getUnbufferedRow('array'))
{
$csv->fputcsv($row);
}

$db->resultMode = MYSQLI_STORE_RESULT; // return to default mode
Expand Down

0 comments on commit 9453c7c

Please sign in to comment.