473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Speciality in mysql_fetch_array

Dear all,

I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().

I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() return data in numeric as well as in associative
array.

But my question is, why it returns in both format. Is it wastage of
memory ?
Why this wastage is necesarry ?

Thanks in advance.

BYe.
Nov 26 '07 #1
4 1757
pradeep wrote:
Dear all,

I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().

I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() return data in numeric as well as in associative
array.

But my question is, why it returns in both format. Is it wastage of
memory ?
Why this wastage is necesarry ?
Hi,

The answer is simple, if you want an assoc array, you can use
mysql_fetch_array().

I always prefer constructs like this in my code:
echo $row["firstname"];

above

echo $row[3];

Since the former leaves you without doubt which column you are using.
And also: If you expand your query to get more columns, an index of an
array might easily get you confused.

But if you like the array-indexes more, just use them.
I expect there must be less overhead involved when no assoc arrays are
created and returned.

So as far as I can tell: it is not a waste of memory, but it offers you
the choice what you want:
1) faster code/less IO (use only indexes)
2) better readable/more robust code. (use assoc arrays)

just my 2 cent.

Regards,
Erwin Moller
>
Thanks in advance.

BYe.
Nov 26 '07 #2
On 26 Nov, 09:29, pradeep <pwprad...@gmail.comwrote:
Dear all,

I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().

I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() return data in numeric as well as in associative
array.
So you know the difference then
>
But my question is, why it returns in both format. Is it wastage of
memory ?
It returns in both formats because that is what it was built to do.
>Is it wastage of memory ?
It is only a waste if you don't need both array types. If you only
want numeric use mysql_fetch_row(), or you can use msql_fetch_array()
with the MSQL_NUM constant. If you only want associative then use
MSQL_ASSOC.
Why this wastage is necesarry ?

Thanks in advance.

BYe.
Nov 26 '07 #3
Erwin Moller wrote:
pradeep wrote:
>Dear all,

I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().

I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() return data in numeric as well as in associative
array.

But my question is, why it returns in both format. Is it wastage of
memory ?
Why this wastage is necesarry ?

Hi,

The answer is simple, if you want an assoc array, you can use
mysql_fetch_array().

I always prefer constructs like this in my code:
echo $row["firstname"];

above

echo $row[3];

Since the former leaves you without doubt which column you are using.
And also: If you expand your query to get more columns, an index of an
array might easily get you confused.

But if you like the array-indexes more, just use them.
I expect there must be less overhead involved when no assoc arrays are
created and returned.

So as far as I can tell: it is not a waste of memory, but it offers you
the choice what you want:
1) faster code/less IO (use only indexes)
2) better readable/more robust code. (use assoc arrays)

just my 2 cent.

Regards,
Erwin Moller
>>
Thanks in advance.

BYe.
Erwin,

The overhead in creating an associative array is negligible.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 26 '07 #4
Jerry Stuckle wrote:
Erwin Moller wrote:
>pradeep wrote:
>>Dear all,

I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().

I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() return data in numeric as well as in associative
array.

But my question is, why it returns in both format. Is it wastage of
memory ?
Why this wastage is necesarry ?

Hi,

The answer is simple, if you want an assoc array, you can use
mysql_fetch_array().

I always prefer constructs like this in my code:
echo $row["firstname"];

above

echo $row[3];

Since the former leaves you without doubt which column you are using.
And also: If you expand your query to get more columns, an index of an
array might easily get you confused.

But if you like the array-indexes more, just use them.
I expect there must be less overhead involved when no assoc arrays are
created and returned.

So as far as I can tell: it is not a waste of memory, but it offers
you the choice what you want:
1) faster code/less IO (use only indexes)
2) better readable/more robust code. (use assoc arrays)

just my 2 cent.

Regards,
Erwin Moller
>>>
Thanks in advance.

BYe.

Erwin,

The overhead in creating an associative array is negligible.
Hi Jerry,

I expected so much, but never actually measured it, since I always use
assoc retrieval of columns for clearity of code.
A task must be very daunting to optimize in this kind of way.

But thanks for the info. Now I know I'll never use indexed row
retrieval. ;-)

Regards,
Erwin
Nov 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: james | last post by:
I am new to PHP and am trying to run a simple query and display the result, with no luck. Here is the code I am using. <?php //start session session_start(); //store cmpid from querystring...
4
by: Theo | last post by:
hi all this is probably another simple one, but the web doesnt seem to have an answer that I can find. Veeeery simple code. each row has 10 columns. require('db.php'); $query = "SELECT *...
15
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
2
by: Dave Moore | last post by:
Hi All, I've got a simple query hopefully somebody can clear up for me. I need to make a query on a database to select a set of table rows, using something like: $result = mysql_query($query);...
4
by: Marcel Brekelmans | last post by:
Hello, I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example: I have a simple table 'tblName': ID Name 1 Jane 2 Joe 2 Doe
9
by: Petr Vileta | last post by:
Hi, I'm new here and excuse me if this question was be here earlier. I have a simple code <html><body> <?php <?php $link = mysql_connect("localhost", "user", "password") or die("Grr: " ....
3
by: monomaniac21 | last post by:
hi all im querying a db for two rows which are always returned. how can i reference each row and output its contents without using a while loop. ive tried: $row = mysql_fetch_array($result);...
2
by: Karl Groves | last post by:
I'm trying to run mysql_fetch_array with a variable in place of the optional result type constant, like so mysql_fetch_array($result, $rtype) where, obviously, $rtype is one of the three valid...
2
by: William Gill | last post by:
given the query: SELECT * FROM customers left join addresses on customer.cusid=addresses.cusid The mysql monitor returns all fields from both tables, including repeating the field matching...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.