Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PHP/MySQL question

tvientitvienti Posts: 230Member
Hey folks,

I just need some clarification on something. MySQL takes care of persistent connections for us. Does this mean that if I connect with mysql_connect, and then call a function that also does (the function being unaware of wether or not it's already connected), no harm is done and no significant time is wasted? Or maybe there's a way to test if there's a connection to a specified server?

Thanks,
Tvienti

Comments

  • JonathanJonathan Posts: 2,914Member
    : I just need some clarification on something. MySQL takes care of persistent connections for us. Does this mean that if I connect with mysql_connect, and then call a function that also does (the function being unaware of wether or not it's already connected), no harm is done and no significant time is wasted? Or maybe there's a way to test if there's a connection to a specified server?
    :
    Actually it's PHP that takes care of the connections. It maintains a connection pool, which contains handles etc for all the connections it has open. To use persistent connections you have to use mysql_pconnect in place of mysql_connect. See:-
    http://uk.php.net/manual/en/function.mysql-pconnect.php

    This looks in the connection pool to see if we already have a connection to the required host and database (as the required user). If not, it opens one and places it in the pool. If so, it uses that connection handle.

    When you call mysql_close on a handle opened with pconnect, the connection is not really closed, it's just held onto in the pool.

    Hope this clears it up for you,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • DarQDarQ Posts: 1,625Member
    just a sidenote;

    a persistant connection (mysql_pconnect) _should_ not be used if you don't know what it actually is. there is in most cases no reason to use pconnect instead of connect.
    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    NEW url--> http://mark.space.servehttp.com

  • JonathanJonathan Posts: 2,914Member
    : just a sidenote;
    :
    : a persistant connection (mysql_pconnect) _should_ not be used if you
    : don't know what it actually is. there is in most cases no reason to
    : use pconnect instead of connect.
    AFAIK, pconnect is somewhat (and possibly very much) more efficient and provided the PHP hackers implemented it well should *in general* be a drop-in replacement for connect. Provided your connection string is consistent I doubt there will be a problem using pconnect, and there's plenty to win. Establishing a database connection is *not* cheap in terms of resources, so as far as I can see there is a very good reason to use pconnect instead of connect. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.