Forum Moderators: coopster

Message Too Old, No Replies

mysqli version of mysql result()?

         

dhardisty

9:17 pm on Jan 7, 2007 (gmt 0)

10+ Year Member



I've been coding in PHP4 for a couple years, and I'm doing my first project in PHP5 right now. I'm using the mysqli class (http://us3.php.net/mysqli).

My question is: is there a mysqli version of the old mysql_result function? Sometimes I just want to get a specific item of data and load it into a variable. With the regular mysql fuctions, it could go like this:

$newvar = mysql_result(mysql_query("select newvar from table where id=1",$db),0,'newvar');

but now, the shortest way I can find to do this is:

$res = $db->query("select newvar from table where id=1");
$row = $res->fetch_assoc();
$newvar = $row[0];

If you know a better way to do this in PHP5 while using mysqli (object style), please let me know.

thanks,
Dave

eelixduppy

11:39 pm on Jan 7, 2007 (gmt 0)



I don't think there is a shorter way of doing this, however, I don't use this extension. What you have looks good to me.

And they call is "Improved"... ;)

dhardisty

8:19 am on Jan 8, 2007 (gmt 0)

10+ Year Member



Thanks for the feedback -- I guess I'll just continue with the multi-line version.

You're right... I don't see what's so improved about mysqli except that it's possible to use it in an object oriented fashion.

coopster

1:42 pm on Jan 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There is a Zend tutorial
ext/mysqli: Part I - Overview and Prepared Statements [devzone.zend.com]
that discusses the "new" extension and might provide some insight.