Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: php and mysql

  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php and mysql

    If i start a mydql connection and store some data as variables, can i open a new connection ? WIll the first connection close or how do i do dhtis

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    No, you can have more than one connection at once.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you use a standard textbook mysql_connect() without the new_link parameter set to True, then no new connection will be openend on your second (and following) mysql_connect() calls.

    this is also very sensible of php, because why would you need a second connection? during the scriptexecution, php will keep using the same connection and then close it automatically when the script is finished. this way, you avoid a lott of overhead because you don't need to keep opening and closing connections.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Why would you need more then one connection, can't you just use one and re-select a database? Never tried it so I'm not sure about that one lol.

  • #5
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    because i have 2 games, want 1 to relate to the other through a contest, so, i need to acces my toher databse to do so

  • #6
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As long as both db's are on the same server, you can use the same connection and switch between them with mysql_select_db().

    You don't even have to do this, though, as you can determine the db you're using directly in the query:

    Code:
    SELECT
     foo
    FROM
     databasename.tablename

  • #7
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •