473,789 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Speciality in mysql_fetch_arr ay

Dear all,

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

I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_arr ay() 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 1769
pradeep wrote:
Dear all,

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

I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_arr ay() 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_arr ay().

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...@gmai l.comwrote:
Dear all,

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

I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_arr ay() 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_arra y()
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_arr ay() and
mysql_fetch_ro w().

I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_ar ray() 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_arr ay().

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*******@attgl obal.net
=============== ===

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

I want to know the difference between mysql_fetch_arr ay() and
mysql_fetch_r ow().

I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_a rray() 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_ar ray().

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
2029
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 $_SESSION = $_GET;
4
7022
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 * FROM mytable";
15
2689
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
6107
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); I can then use mysql_fetch_array in a while loop to access each row in the result. This all works fine.
4
2966
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
7432
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: " . mysql_error()); mysql_select_db("my_dbf") or die("Grr");
3
7504
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); extract $row; echo $var1; //var 1 of row 0 echo $var1; //var 1 of row 1
2
4640
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 values for the result type. This throws an error: "mysql_fetch_array() : The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH." I'm not quite sure what the issue here is, other than that I'm replacing a constant with a...
2
1655
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 the on condition (cusid). mysql_fetch_array() does not return the matching field from the joined
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10374
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4078
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2898
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.