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 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stop mysql connection

    Hi
    I cant seem to get this code to work for me, I want to stop mysql connection if a name exist on my database, can someone tell me what I'm doing wrong)


    PHP Code:
    $connection mysql_connect(localhost,xxxx_xx,xxxx) or die ("Couldn't connect to server."); 
    $db mysql_select_db(xxxx_xxx$connection) or die ("Couldn't select database."); 
    $sql "SELECT Bloom_Name FROM ihsreg WHERE Bloom_Name = '$BloomName'"
    $result mysql_query($sql) or die("Couldn't execute query. "mysql_error());$num mysql_numrows($result); 
    if (
    $num 0
          { 
            
    $name_exist "$BloomName already Registered. Select another Name."
            echo 
    $name_exist;
         
    mysql_close($connection);
          }
    else
            
    $name_ok "$BloomName is not a Registered. You may use this Name."
            echo 
    $name_ok
    $query="insert into ihsreg 

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    What exactly are you trying to do? Are you sure you want to close the connection to the DB? If you close the connection that means the user can not interact with the database anymore until you open it back up. I can't remember right now but I think that the connection to the DB closes at the end of the script automatically anyway.

    Is there a specific reason as to why you need to explicitly close the connection within your IF statement?
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I put all activities concerning with database into different small functions, I connect and select DB inside them, so if my function exits, connection variable will be destroyed,isn't it?Do I have to explicitly close the connection like above code ?

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    please don't hijack this thread.
    start a new one if you have a question of your own.
    Quote Originally Posted by funhunter
    I put all activities concerning with database into different small functions, I connect and select DB inside them, so if my function exits, connection variable will be destroyed,isn't it?
    i don't realy understand your question. but if you use the mysql_connect() inside a function, then there will still be only one connection opened in your script (unless you set the new-connection parameter in your mysql_connect() but i've never seen anyone do that)
    Quote Originally Posted by funhunter
    Do I have to explicitly close the connection like above code ?
    No. The connection will automatically be closed at the end of your script.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Yes. The connection is closed automagically at the end of the script unless you use mysql_pconnect() which means that it is a persistent connection that you should close using mysql_close.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by StupidRalph
    Yes. The connection is closed automagically at the end of the script unless you use mysql_pconnect() which means that it is a persistent connection that you should close using mysql_close.
    that's not correct.
    mysql_close() does not close persistent 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

  • #8
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Quote Originally Posted by raf
    that's not correct.
    mysql_close() does not close persistent connections
    What am I thinking ..its persitent it doesn't close.

    persistent -(adj.) Never-ceasing 2. Continually recurring to the mind. 3. Retained; not shed.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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