note 109782 modified in class.mysqli-result by danbrown

From: Date: Fri, 31 Aug 2012 15:50:08 +0000
Subject: note 109782 modified in class.mysqli-result by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190342@lists.php.net to get a copy of this message
Converting an old project from using the mysql extension to the mysqli extension, I found the most annoying change to be the lack of a corresponding mysql_result function in mysqli. While mysql_result is a generally terrible function, it was useful for fetching a single result field *value* from a result set (for example, if looking up a user's ID).

The behavior of mysql_result is approximated here, though you may want to name it something other than mysqli_result so as to avoid thinking it's an actual, built-in function.

<?php
function mysqli_result($res, $row, $field=0) {
	$res->data_seek($row);
	$datarow = $res->fetch_array();
	return $datarow[$field];
}
?>

Implementing it via the OO interface is left as an exercise to the reader. --was-- Converting an old project from using the mysql extension to the mysqli extension, I found the most annoying change to be the lack of a corresponding mysql_result function in mysqli. While mysql_result is a generally terrible function, it was useful for fetching a single result field *value* from a result set (for example, if looking up a user's ID). The behavior of mysql_result is approximated here, though you may want to name it something other than mysqli_result so as to avoid thinking it's an actual, built-in function. function mysqli_result($res, $row, $field=0) { $res->data_seek($row); $datarow = $res->fetch_array(); return $datarow[$field]; } Implementing it via the OO interface is left as an exercise to the reader. http://php.net/manual/en/class.mysqli-result.php

« previous php.notes (#190342) next »