GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  PHP
Go To First  |  Previous Question  |  Next Question 
 PHP  |  Question 11 of 74    Print  
what is difference between mysql_fetch_array(),mysql_fetch_row() and mysql_fetch_object()
please insert with example

  
Total Answers and Comments: 7 Last Update: October 03, 2009     Asked by: mrbaliram 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: atul kumar pal
 
mysql_fetch_row ::Return row as aan enumrated array and each line contain a unique ID .example.
$result=mysql_query($query);
while($row=mysql_fetch_row($result))
{
print "$row[0]";
print "$row[1]";
print "$row[2]";
}

mysql_fetch_array ::Return row as anassociative or an enumrated array or both which is default .you can refer to outputs as databases fieldname rather then number .example.
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
print "$row['name']";
print "$row['address']";
print "$row['city']";
}

mysql_fetch_object  :: it return as an object on the place of array.

$result=mysql_query($query);
while($row=mysql_fetch_object($result))
{
print "$row->name";
print "$row->address";
print "$row->city";
}

Above answer was rated as good by the following members:
varunk2006, brijbhushansh, ravikumar.drk
June 26, 2006 07:28:08   #1  
Geetan        

RE: what is difference between mysql_fetch_array(),mys...

what is difference between mysql_fetch_array() mys...

mysql_fetch_array():: fetches a result row as a associated array numeric array

mysql_fetch_object: Fetaches a result row as object.

mysql_fetch_row::fetches a result row as array


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 30, 2006 04:08:16   #2  
mahalingam        

RE: what is difference between mysql_fetch_array(),mys...

mysql_fetch_object -> Fetch the first single matching record of results.

mysql_fetch_array -> Fetch the all matching records of results.


 
Is this answer useful? Yes | No
February 14, 2007 17:23:19   #3  
Deepak Radhakrishnan        

RE: what is difference between mysql_fetch_array(),mys...
mysql_fetch_row Get a result row as an enumerated arrayEach column has to be accessed as $row[0] $row[1] etcmysql_fetch_array Fetch a result row as an associative array a numeric array or both$row[0] or $row['user_id']both field name or enumerated array value can be usedmysql_fetch_object Fetch a result row as an object$row->user_id $row->pass etc
 
Is this answer useful? Yes | No
June 04, 2007 03:02:37   #4  
atul kumar pal        

RE: what is difference between mysql_fetch_array(),mys...
mysql_fetch_row ::Return row as aan enumrated array and each line contain a unique ID .example.
$result mysql_query($query);
while($row mysql_fetch_row($result))
{
print $row[0] ;
print $row[1] ;
print $row[2] ;
}

mysql_fetch_array ::Return row as anassociative or an enumrated array or both which is default .you can refer to outputs as databases fieldname rather then number .example.
$result mysql_query($query);
while($row mysql_fetch_array($result))
{
print $row['name'] ;
print $row['address'] ;
print $row['city'] ;
}

mysql_fetch_object :: it return as an object on the place of array.

$result mysql_query($query);
while($row mysql_fetch_object($result))
{
print $row->name ;
print $row->address ;
print $row->city ;
}

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
August 05, 2007 02:30:05   #5  
shadab        

RE: what is difference between mysql_fetch_array(),mys...

Let's take one example :
one table says
create table student
(id int(5)
name varchar(50));

mysql_fetch_array:

--> it returns array as index as table field name as well as it's index number
from table student you fetch record like this:
while($res mysql_fetch_array($rs)){

echo $res['id'] ;// print id value
or
echo $res[0];// same as above statement



}

mysql_fetch_row:
--> it returns array as it's index number
from table student you fetch record like this:
while($res mysql_fetch_array($rs)){


echo $res[0];// it can fetch value by index value not table field name



}



mysql_fetch_object
--> it returns array as it's as object as table field name
from table student you fetch record like this:
while($res mysql_fetch_array($rs)){


echo $res->id;// it can fetch value by object value not table field name or it's //index



}


 
Is this answer useful? Yes | No
May 07, 2009 04:26:21   #6  
belalansari23 Member Since: May 2009   Contribution: 1    

RE: what is difference between mysql_fetch_array(),mysql_fetch_row() and mysql_fetch_object()please insert with example
I will try to make you understand following points.

mysql_fetch_row: Returns row as an enumerated array
mysql_fetch_object: Returns row as an object
mysql_fetch_array: Returns row as an associative array

This is the table details
------------------------------------------------------
ID Name City
---------------------------------------------
1 belal Chatar
2 Sharma Ranchi
3 chand Bachra
------------------------------------------------------
$res select * from details ;
$row mysql_fetch_row($res) // this return enumerated array having value

row{
1
belal
chatra
}
so we can print $row[0] $row[1] $row[2];

in case of mysql_fetch_array() . It return accociative array.
like.
row['id'] 1
row['name'] belal ;
row['city'] Chatar ;

Bela Ansari




 
Is this answer useful? Yes | No
October 01, 2009 14:48:02   #7  
samson_noel_1980 Member Since: October 2009   Contribution: 1    

RE: what is difference between mysql_fetch_array(),mysql_fetch_row() and mysql_fetch_object()please insert with example

mysql_fetch_array returns the array and you can only access the database fields as array but not by their names but mysql_fetch_objewct returns the object and you can access the fields by using their names.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape