Reply to Re: !Need advice from other PHP developers.

Your name:

Reply:


Posted by Erwin Moller on 02/05/07 08:56

Eric Layman wrote:

> Hi,
>
> Many years ago when I first learnt abt web dev in school,
>
> I was taught this methodology:
>
> [Open connection]
>
> <html>
> blah blabh
>
> [execute sql]
> [loop thru recordset]
>
> <table>[data] </table>
>
> [recordset close]
> [end loop]
>
> <html>
>
> [Close connection]
>
>
> Over the peroid of time, I noticed that the above method may cause
> connection problems on heavy sites.
>
> Recently, I have use another method to retrieve data from server
>
> [Open Connection]
> [declare 2D array]
> [loop thru recordset]
> [2D array] = [data]
> [recordset.close]
> [end loop]
> [Close connection]
>
> <html>
>
> [loop thru the 2D array]
> <table>[2d array's DATA] </table>
> [end array loop]
>
> </html>
>
> It performs better as all the data retrieveal and processing are all
> processed at the beginning of the page.

Hi,

That is how I retrieve data too, via ADODB (PHP) GetArray().
Nothing wrong with it. It even offers you handy last minute scrubbing over
an array instead of awkward recordsets.

>
> Need comments and advise please.
>
> 1. Are there better ways to manage connections and easier data retrieval
> to ensure performance of the site under heavy load?

PHP recycles its connection behind your back.
If scriptA.php connects to a database, a connection is build based on the
login-credentials (host, database, username, password, etc).

If scriptB.php, scriptC.php, etc, use the same logincredentials, which is
almost always the case in webdriven databases, you'll find that they do NOT
need the connection/authentication overhead that scriptA.pp needed.
PHP remembers the logincredentials, DOESN'T CLOSE ITS CONNECTION, and
recycles the connection when ANY script uses the same logincredentials.
So PHP is doing things right performancewise.
I don't think you'll gain a lot of performanceimprovement by using another
approach.


>
> 2. Are there any potential pitfalls regarding my 2nd method of data
> retrieval?

Just be aware how your elements in your array represent 'strange values'
coming from the database, like NULL. Are they stored as empty string? Or
are they really (PHP)NULL? Make sure you check and know.

>
> Thanks
>
>


Regards,
Erwin Moller

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация