What is the difference between mysql_fetch_object and mysql_fetch_array?
Mysql_fetch_object returns the result from the database as objects while mysql_fetch_array returns result as an array. This will allow access to the data by the field names.
Example:Using mysql_fetch_object field can be accessed as $result->name and using mysql_fetch_array field can be accessed as $result->[name]
Explain the ways to retrieve the data in the result set of MySQL using PHP.
Ways to retrieve the data in the result set of MySQL using PHP
1. mysql_fetch_row($result): where $result is the result resource returned from a successful query executed using the mysql_query() function.
Example:$result = mysql_query(“SELECT * from students);
while($row = mysql_fetch_row($result))
{
Some statement;
}
2. mysql_fetch_array($result): Return the current row with both associative and numeric indexes where each column can either be accessed by 0, 1, 2, etc., or the column name.
Example:$row = mysql_fetch_array($result)
3. mysql_fetch_assoc($result): Return the current row as an associative array, where the name of each column is a key in the array.
Example:$row = mysql_fetch_assoc($result)
$row[‘column_name’]
What is the difference between mysql_fetch_object and mysql_fetch_array in PHP?
mysql_fetch_object: Results are objects returned from database. Fields are accessible like
$result->name, $result->cust_name, where $result is the result object and name, cust_name are the fields.
mysql_fetch_array : Results are arrays returned from database. Fields are accessible like $result[name], $result[cust_name].