Fetching one row only with MySQLi

oaziz picture oaziz · Jan 17, 2012 · Viewed 59k times · Source

How can I only fetch one INDEXED row with MySQLi? I'm currently doing this:

$row = $result->fetch(MYSQLI_ASSOC);
$row = $row[0];

Is there another way?

I'm aware of mysqli_fetch_row but it doesn't return an associative array.

Answer

You Qi picture You Qi · Jan 17, 2012

Use $row = $result->fetch_assoc(); - it's the same as fetch_row() but returns an associative array.