473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is this a good idea?

Hi!

I've been programming ASP for 5 years and am now learning PHP.
In ASP, you can use GetRows function which returns 2 by 2 array of
Recordset.
Actually, it's a recommended way in ASP when you access DB as it
disconnects the DB earlier.
Also, it's handy as you can directly access any data in the array
without looping.

As far as I know, there's no such function in PHP and I can make one.
My question is whether it's good in PHP.

pseudo-code:

$data = get_data("selec t * from table1");
$var = $data[3][2]; //value at 4th row, 3rd column

This way, I can wrap db connection, data retrieval, and error handling
with one function (or maybe a class).
Is the idea workable?

TIA.
Sam

Jan 17 '06
54 3654
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chung Leong wrote:
[refactoring] [...] By definition, you are not adding new
functionality--hence value to the product. You are thus wasting
programming and QA resource. Moreover, you risk introducting bugs into
what was working before. It's a lose-lose proposition.

As every good engineer knows, if it ain't broken, don't fix it.
But, if it's broken, I'd better fix it for good, instead of patching legacy
code so that it "just works".

The isue we're discussing - dumping the entire query results into an array
in memory - induces lazyness in the programmers. Lazyness leads to more
complex code, more complex code leads to more bugs, more bugs leads to more
wasted QA time when something breaks down.

A few MB of memory per script may seem a small issue, but think about a
few MB per script, 100 scripts per second.


That's just unrealistic. When you retrieve data from the database, it
usually goes somewhere--i.e. to the client.


Sometimes it does not - sometimes, due to lazy programming or bad DB design,
data goes into memory, goes out of memory. And the whole thing risks
becoming a GIGO.

(but, hey, it's a "it just works" scenario! it's good for the CEO! I'm
getting paid!)
In you scenario you'd have a server that output multiple gigs per-second.
I don't know about you but I certainly don't have a peta-byte bandwidth
quota.


No; in my scenario I'll just have a couple of Gigabit-ethernet-enabled
servers. And their bottleneck must be the bandwith, not the resource-hungry
scripts. The code must be so flazing fast, so fucking clean, that I'm able
to affirm the server will be able to handle the load and not choke.

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Donde se pierde el interés también se pierde la memoria.
-- Johann Wolfang Von Goethe. (1749-1832) Escritor alemán.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD0DdA3jc Q2mg3Pc8RAmqiAJ 0RdFNwsQZ1jGA2I pAl71RHNq44RQCf aJtK
gLEzeA51A7KxtWq tK9hxBW0=
=HcH0
-----END PGP SIGNATURE-----
Jan 20 '06 #31
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

R. Rajesh Jeba Anbiah wrote:
<OT>It's really nice to see new comers like Iván Sánchez Ortega
and the c.l.php discussions are now getting hotter:-)</OT>


Newcomer? I've been programming in PHP long before you were born, bro!

:-P

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Las personas obran por interés propio. Incluso cuando servimos a los demás,
solemos hacerlo porque nos reporta beneficios o porque no hacerlo iría en
nuestro propio detrimento. Aunque las personas sacrifiquen su vida por el
prójimo en tiempos de guerra y otras circunstancias extremas, no puede
decirse que ésta sea la norma. Habitualmente, por no decir ante todo, el
altruismo satisface una necesidad propia.
-- Thomas Hobbes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD0DeH3jc Q2mg3Pc8RAkPFAJ 9oenvM626ctrD+n sZktN0ieNz6WQCd G+kL
sZZ+qmt51cKoA9a 0Zbeyvzw=
=Snkm
-----END PGP SIGNATURE-----
Jan 20 '06 #32
Iván Sánchez Ortega wrote:
R. Rajesh Jeba Anbiah wrote:
<OT>It's really nice to see new comers like Iván Sánchez Ortega
and the c.l.php discussions are now getting hotter:-)</OT>


Newcomer? I've been programming in PHP long before you were born, bro!


Hey:-)

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jan 20 '06 #33
Iván Sánchez Ortega wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chung Leong wrote:


But, if it's broken, I'd better fix it for good, instead of patching legacy
code so that it "just works".

The isue we're discussing - dumping the entire query results into an array
in memory - induces lazyness in the programmers. Lazyness leads to more
complex code, more complex code leads to more bugs, more bugs leads to more
wasted QA time when something breaks down.

I disagree completely.

There are many valid reasons for putting the information in an array.

For one thing - once you have it in an array, you can release your
result set - freeing MySQL resources. And if you don't need the
connection for anything else, you can close it. One of the big
concurrency issues with RDB's is holding their resources longer than
necessary.

Also, if you're doing lots of complex processing on the returned data,
it's generally better to buffer the data in your own program rather than
hold it in MySQL.

Your way works for low volume web pages. But once you get into heavy
database use, it's a whole different story.

Sometimes it does not - sometimes, due to lazy programming or bad DB design,
data goes into memory, goes out of memory. And the whole thing risks
becoming a GIGO.

(but, hey, it's a "it just works" scenario! it's good for the CEO! I'm
getting paid!)

You don't need local buffering to make a GIGO. Any poor programming
practice will do it. While no good programming practice will.

No; in my scenario I'll just have a couple of Gigabit-ethernet-enabled
servers. And their bottleneck must be the bandwith, not the resource-hungry
scripts. The code must be so flazing fast, so fucking clean, that I'm able
to affirm the server will be able to handle the load and not choke.

Try it on some of the systems I've worked on in the past. Multiple web
servers feeding off one database server (DB/2 on AIX in this case).
Averages of < 100K > 1M hits/hr.

I've also worked on database systems which can handle peaks of < 1M
database requests per hour. You can't do either if you hold the db
resources unnecessarily long.
- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Donde se pierde el interés también se pierde la memoria.
-- Johann Wolfang Von Goethe. (1749-1832) Escritor alemán.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD0DdA3jc Q2mg3Pc8RAmqiAJ 0RdFNwsQZ1jGA2I pAl71RHNq44RQCf aJtK
gLEzeA51A7KxtWq tK9hxBW0=
=HcH0
-----END PGP SIGNATURE-----

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jan 20 '06 #34
Iván Sánchez Ortega wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

R. Rajesh Jeba Anbiah wrote:

<OT>It's really nice to see new comers like Iván Sánchez Ortega
and the c.l.php discussions are now getting hotter:-)</OT>

Newcomer? I've been programming in PHP long before you were born, bro!

:-P

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Las personas obran por interés propio. Incluso cuando servimos a los demás,
solemos hacerlo porque nos reporta beneficios o porque no hacerlo iría en
nuestro propio detrimento. Aunque las personas sacrifiquen su vida por el
prójimo en tiempos de guerra y otras circunstancias extremas, no puede
decirse que ésta sea la norma. Habitualmente, por no decir ante todo, el
altruismo satisface una necesidad propia.
-- Thomas Hobbes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD0DeH3jc Q2mg3Pc8RAkPFAJ 9oenvM626ctrD+n sZktN0ieNz6WQCd G+kL
sZZ+qmt51cKoA9a 0Zbeyvzw=
=Snkm
-----END PGP SIGNATURE-----

And I've was probably programming before you were born!

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jan 20 '06 #35
Iván Sánchez Ortega wrote:
But, if it's broken, I'd better fix it for good, instead of patching legacy
code so that it "just works".
Then it's not refactoring, my friend.
The isue we're discussing - dumping the entire query results into an array
in memory - induces lazyness in the programmers. Lazyness leads to more
complex code, more complex code leads to more bugs, more bugs leads to more
wasted QA time when something breaks down.
There we go. That's something that always happen in this group--when
unable to afford a defense on technical merits, resort to a value
judgement of sort. There's nothing wrong in choosing an easy solution.
It's called being smart.
Sometimes it does not - sometimes, due to lazy programming or bad DB design,
data goes into memory, goes out of memory. And the whole thing risks
becoming a GIGO.
Using bad programming to justify your so-called "good programming"--now
you're making a whole of sense.
No; in my scenario I'll just have a couple of Gigabit-ethernet-enabled
servers. And their bottleneck must be the bandwith, not the resource-hungry
scripts. The code must be so flazing fast, so fucking clean, that I'm able
to affirm the server will be able to handle the load and not choke.


You don't even know what you're debating. The exact same amount of work
is done. There is no performance impact unless the memory usage exceeds
the physical amount available. A typical database query will return 10K
or less. To say that reading the data into an array would somehow have
some castatrophe effect on performance is...intellectu ally challenged.

Jan 20 '06 #36
Chung Leong wrote:
<snip>
There is no performance impact unless the memory usage exceeds
the physical amount available. A typical database query will return 10K
or less. To say that reading the data into an array would somehow have
some castatrophe effect on performance is...intellectu ally challenged.


Some crazy predictions of the future of this thread:
Chung gonna prove his ideas with his own (benchmarking?) script and I
gonna ask him to use APD and other real tools, some curmudgeon gonna
claim more than 100 years of experience without reading the thread, and
.....

(Discussions in c.l.php are not that hard to imagine;-) Pun intended,
not meant to be serious.)

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jan 20 '06 #37
R. Rajesh Jeba Anbiah wrote:

Some crazy predictions of the future of this thread:
Chung gonna prove his ideas with his own (benchmarking?) script and I
gonna ask him to use APD and other real tools, some curmudgeon gonna
claim more than 100 years of experience without reading the thread, and
....


What I am going to say is this: *never* listen to the advice of R.
Rajesh Jeba Anbiah because it will shrink your dick. Unless someone can
prove otherwise (benchmarking?) , we should assume my assertion is true.

Jan 20 '06 #38

Jerry Stuckle wrote:
For one thing - once you have it in an array, you can release your
result set - freeing MySQL resources. And if you don't need the
connection for anything else, you can close it. One of the big
concurrency issues with RDB's is holding their resources longer than
necessary.

Also, if you're doing lots of complex processing on the returned data,
it's generally better to buffer the data in your own program rather than
hold it in MySQL.


It doesn't have to be complex, just time-consuming. An operation like
echo can potentially block for a very long time.

Jan 20 '06 #39
Chung Leong wrote:
R. Rajesh Jeba Anbiah wrote: <snip> What I am going to say is this: *never* listen to the advice of R.
Rajesh Jeba Anbiah because it will shrink your dick. Unless someone can
prove otherwise (benchmarking?) , we should assume my assertion is true.


LOL:-)

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jan 21 '06 #40

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

Similar topics

24
3615
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works, first and foremost. If it works well, even better. The same goes for ease of maintenance, memory footprint, speed, etc, etc. Most of the time, people are writing code for a use in the *real world*, and not just as an academic exercise. Look at...
12
15527
by: Generic Usenet Account | last post by:
I am going through some legacy code that has an "isNull()" method defined on certain classes. I can see that this can be a good way to eliminate certain types of crashes, by making this the first call in a method (and bailing out immediately if it is true). However, if this is such a good idea, why is it not common industry practice? Mohan
14
4650
by: dreamcatcher | last post by:
I always have this idea that typedef a data type especially a structure is very convenient in coding, but my teacher insisted that I should use the full struct declaration and no further explanations, so I wonder is there any good using typedef ? and I also know that when a data type being typedefed become an abstract data type, so what exactly is an abstract data type, is it any good ? -- Posted via http://dbforums.com
43
2665
by: Sensei | last post by:
Hi! I'm thinking about a good programming style, pros and cons of some topics. Of course, this has nothing to do with indentation... Students are now java-dependent (too bad) and I need some serious motivations for many issues... I hope you can help me :) I begin with the two major for now, others will come for sure! - function variables: they're used to java, so no pointers. Personally I'd use always pointers, but why could be better...
150
6582
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and see if you agree with my opinion or not. Tony Marston http://www.tonymarston.net
0
1097
by: Charles D Hixson | last post by:
I was reading through old messages in the list and came up against an idea that I thought might be of some value: "Wouldn't it be a good idea if one could "rewind" an iterator?" Not stated in precisely those terms, perhaps, but that's the way I read it. I appreciate that one could use a sequence rather than an iterator, and that I don't understand the implementation issues. (They don't look large, but what to I know?) But would it be...
2
1430
by: pigeonrandle | last post by:
Hi, My application creates a project that is structured like a tree, so i want to use a treeview to display it to the user. Would it be a good idea to create the various parts of project as classes inherited from TreeNode and then just add them to the treeview (ie adding extra properties to the inherited classes to hold my data)? This would make outputting the project as an xml file very simple as i could just traverse the treeview and...
7
2300
by: elgiei | last post by:
Good morning at all, i have to implement a server,that every n-seconds (eg. 10sec) sends to other clients,which files and directory has been deleted or modified. i build a n-tree, for each files on harddisk there's a node into n- tree, this solution is not good for large hard disk.. and i can't use inotify (it's forbidden), and only c solutions are accepted without third party software or external calls.
5
1704
by: mike3 | last post by:
Hi. Is this a good idea?: <begin code> /* Addition operator: += */ const BigFix &BigFix::operator+=(const BigFix &rhs) { ErrorType err; int lhs_sign = sign, rhs_sign = rhs.sign;
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
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...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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...
0
8937
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
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
5355
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
4012
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
3
2852
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.