Organizational Research By

Surprising Reserch Topic

Difference between mysql_fetch_object and mysql_fetch_array in PHP



asked Sep 13, 2013 in PHP by ashish singh
edited Sep 12, 2013
0 votes
53 views



Related Hot Questions

1 Answer

0 votes
difference between mysql_fetch_object and mysql_fetch_array in PHP
 
mysql_fetch_object :
mysql_fetch_object returns the results from database as objects.(fetches a result row as object)
$result->email 
 
 
 
Example:
mysql_connect("host", "username", "pwd");
mysql_select_db("db");
$result = mysql_query("select * from employees");
while ($rows = mysql_fetch_object($result))
{
    echo $empname=$row->name;
    echo "
";
   echo $empmail=$row->email;
}
?>
Output: 
Boostr
knowledge@example.com
 
mysql_fetch_array:
Fetch a result row as an associative array, a numeric array, or both
$row[0],$row["name"]; 
 
Example:
mysql_connect("host", "username", "pwd");
mysql_select_db("db");
$result = mysql_query("select * from employees");
while ($rows = mysql_fetch_array($result))
{
    echo $empname=$row[0];
echo "
";
   echo $empmail=$row["email"];
}
 
 
?>
Output: 
boostr
knowledge@example.com
answered Sep 13, 2013 by ashish singh
edited Sep 12, 2013

...