Tuesday, December 2, 2008

What is the difference between mysql_fetch_array() and mysql_fetch_assoc() - which is faster?

Lets see an example.

Lets think we have a table with following fields,
id
name
age

Now when you use mysql_fetch_array() it will return both numeric array and an associative array.


while($data = mysql_fetch_array($result))
{
//will return

$id = $data[0];
$id = $data['id'];

$name = $data[1];
$name = $data['name'];

$age = $data[2];
$age = $data['age'];

}


when you use mysql_fetch_assoc() it will return only an associative array.


while($data = mysql_fetch_assoc($result))
{
// will return

$id = $data['id'];
$name = $data['name'];
$age = $data['age'];

}



So mysql_fetch_assoc() is comparatively faster because its only return a associative array.

Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

No comments:

Post a Comment