Ulf Wendel

PHP: ext/mysqli result sets and foreach()

What does any developer do during a train trip? Correct, he’s hacking. He’s at least working on bells and whistles such as foreach() support for buffered ext/mysqli result sets in mysqlnd. Thanks Andrey!

$link = mysqli_connect('host', 'user', 'password');
$res = mysqli_query($link, 'SHOW TABLES FROM mysql');
foreach ($res as $row)
  var_dump($row);
mysqli_free_result($res);
mysqli_close($link);

Note: SVN/CVS only, mysqlnd only, buffered result sets only, no way to enforce any other fetch mode but MYSQLI_FETCH_ASSOC – but quite handy anyway.

Comments are closed.