Re: Avoid to open mysql querries then times in the page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yep, though I would still query 2x. Once for the login data, no sense
retrieving more if the log on fails. Then the second query is to get
all the user data into a session object. There are two schools of
thought about this, pull all the required data into the session, which
doesn't scale well but if your site is not that busy, it won't matter
all that much. The other option is to query each time the user needs
some data and just keep the user_id in the session and run small quick
queried to get the data you need.

This is where you need to understand architectural trends. The REST
architecture is all about true stateless application design where the
app does not use sessions which allows for massive horizontal scaling.
The app could connect to any server in the environment for access to
the data and any server could deliver any data.  Many large scale
applications use this design to scale out. Facebook is one.

Be honest about how busy the site will be and use that as a guiding
principle, but build it in layers to make swapping out bits easier.

Hth



On 5/4/09, Matthieu <spamamis@xxxxxxxxx> wrote:
> Hello,
>
> I'm a totally newbie to php/Mysql but I'd like to know if it is normal that
> I have to connect 3 times to the db in one page.
>
> For example, I have
>
> 1. A connection for the login / pass a $_SESSION['login'] before the HTML
> tags
>
> 2. I need to say hello to the user so I reconnect, run a query to select the
> user having the login and echo 'Hello '.$user['login'].'!''
>
> 3. I need to show him his friends a bit later, so I have to connect a last
> time and re-run a querry because I can't use the data $user that I used in
> my upper php code...
>
>
> Is there a walkthroug to have only one connection for the page?
>
> Thanks
>
> Matthieu
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 

Bastien

Cat, the other other white meat

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux