473,511 Members | 17,486 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do mysql_fetch_assoc/mysql_query work?

How do mysql_query() and mysql_fetch_assoc() actually work?

When I submit a query to a MySQL database it goes away, works out what
I requested and throws it back at me. When I submit a query using PHP I
submit the query using mysql_query and then iterate through the result
set sing mysql_fetch_assoc() (or mysql_fetch_array() or
mysql_fetch_row()). What is the purpose of mysql_fetch_xxxx()? Why
can't mysql_query return a two dimensional array? What trickery is
going on?

Aug 25 '06 #1
3 5347
sm******@hotmail.com wrote:
How do mysql_query() and mysql_fetch_assoc() actually work?

When I submit a query to a MySQL database it goes away, works out what
I requested and throws it back at me. When I submit a query using PHP I
submit the query using mysql_query and then iterate through the result
set sing mysql_fetch_assoc() (or mysql_fetch_array() or
mysql_fetch_row()). What is the purpose of mysql_fetch_xxxx()? Why
can't mysql_query return a two dimensional array? What trickery is
going on?
Maybe you don't want a 2D array? And what happens if the database
returns a few hundred K rows? Or even a 1k rows with 10K data in each
row. You can rapidly use up a lot of memory that way.

Most of the time I only access one row at a time, and don't need to go
back to a previous row anyway. And when I do I can put everything (or
at least the data I want) in an array.

It also gives me the ability to access the data by the relative position
in the returned row, by the column name, or both. And if I only need
one [i.e. column name], it's more efficient to use only one.

And I'm not sure which language you're talking about when you say " When
I submit a query to a MySQL database it goes away, works out what I
requested and throws it back at me.". Even in C/C++ you need to use
mysql_fetch_row. What language are you using?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 25 '06 #2

Jerry Stuckle wrote:
sm******@hotmail.com wrote:
How do mysql_query() and mysql_fetch_assoc() actually work?

When I submit a query to a MySQL database it goes away, works out what
I requested and throws it back at me. When I submit a query using PHP I
submit the query using mysql_query and then iterate through the result
set sing mysql_fetch_assoc() (or mysql_fetch_array() or
mysql_fetch_row()). What is the purpose of mysql_fetch_xxxx()? Why
can't mysql_query return a two dimensional array? What trickery is
going on?

Maybe you don't want a 2D array? And what happens if the database
returns a few hundred K rows? Or even a 1k rows with 10K data in each
row. You can rapidly use up a lot of memory that way.

Most of the time I only access one row at a time, and don't need to go
back to a previous row anyway. And when I do I can put everything (or
at least the data I want) in an array.

It also gives me the ability to access the data by the relative position
in the returned row, by the column name, or both. And if I only need
one [i.e. column name], it's more efficient to use only one.

And I'm not sure which language you're talking about when you say " When
I submit a query to a MySQL database it goes away, works out what I
requested and throws it back at me.". Even in C/C++ you need to use
mysql_fetch_row. What language are you using?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
I think it's the SQL language?
I think it's not a question of arrays and memory used, it's the
difference between procedural and non-procedural.
Maybe there should be some kind of textarea gizmo in php/html
that just yields brute results like the MySQL console does.

Aug 25 '06 #3
universalbitmapper wrote:
Jerry Stuckle wrote:
>>sm******@hotmail.com wrote:
>>>How do mysql_query() and mysql_fetch_assoc() actually work?

When I submit a query to a MySQL database it goes away, works out what
I requested and throws it back at me. When I submit a query using PHP I
submit the query using mysql_query and then iterate through the result
set sing mysql_fetch_assoc() (or mysql_fetch_array() or
mysql_fetch_row()). What is the purpose of mysql_fetch_xxxx()? Why
can't mysql_query return a two dimensional array? What trickery is
going on?

Maybe you don't want a 2D array? And what happens if the database
returns a few hundred K rows? Or even a 1k rows with 10K data in each
row. You can rapidly use up a lot of memory that way.

Most of the time I only access one row at a time, and don't need to go
back to a previous row anyway. And when I do I can put everything (or
at least the data I want) in an array.

It also gives me the ability to access the data by the relative position
in the returned row, by the column name, or both. And if I only need
one [i.e. column name], it's more efficient to use only one.

And I'm not sure which language you're talking about when you say " When
I submit a query to a MySQL database it goes away, works out what I
requested and throws it back at me.". Even in C/C++ you need to use
mysql_fetch_row. What language are you using?

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


I think it's the SQL language?
I think it's not a question of arrays and memory used, it's the
difference between procedural and non-procedural.
Maybe there should be some kind of textarea gizmo in php/html
that just yields brute results like the MySQL console does.
Nope, mysql_fetch_array isn't a part of the language :-).

SQL defines the queries to be used. But each database has its own
interface to the application, and they typically vary somewhat between
languages.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 25 '06 #4

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

Similar topics

4
15761
by: Bruce A. Julseth | last post by:
I know the following $sql will fail since there is no Customer='Smith'. I want to determine how to test a failure of mysql_query. I thought mysql_query returned false if a query failed. The test...
6
4643
by: aa | last post by:
I use the following fragment of code to output datf from MySQL: ====================================================== $chan = mysql_connect ($db_host, $username, $password); mysql_select_db...
5
2914
by: Chameleon | last post by:
I have a SQL Script with about 5000 SQL Commands. How can I send it to SQL Server at once? I see mysql_query() fails on first semicolon (;) who delimits the SQL Commands. Another...
3
4614
by: Paul Lautman | last post by:
Are there any benefits to using mysql_fetch_object() instead of mysql_fetch_assoc()?
2
2352
by: phattymatty | last post by:
I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already been sorted in the array using a...
5
2717
by: clodhoppers18 | last post by:
I am trying to get the following code to work, and I am having some problems: The code goes for actually 110 lines, but I have dismissed what is not needed. The connection and all that works for...
6
10952
by: aerobat | last post by:
hello all just wondering if anyone can help me with this problem. Ii has to do with a simple mysql_query. i have tried so many different ways of doing it, but it wont work. here is the code: ...
1
1758
by: bytesFTW99 | last post by:
Ok I have a problem! i have a mysql_fetch_assoc that does not recognize the NULL value of the column. however, i want this null to be picked up so i can use it. how can i go about doing that? ...
2
16964
by: poreko | last post by:
I am connecting to my database using Object oriented PHP. My query is returning results but at the end of my table,at the bottom of the page I keep having this error when I run my program: Warning:...
0
7356
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
7427
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...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
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...
0
4741
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...
0
3227
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...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
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 ...

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.