Professional Web Applications Themes

simple questions but please answer me - MySQL

Hi, I'm ending my website built with php+mysql. In a first moment I didn't want to use mysql but with the help of some manuals and 'how to' I have learned the most important instructions for my necessities. Only in few articles I have found annotations on the importance to close the access to database after every login and interrogation. In some cases I've found simply this line at the end of the php page: mysql_close($db); in other cases: mysql_free_result($xx); mysql_close($db); in other cases any worry to close the access! In my website every page connects to database, so please ...

  1. #1

    Default simple questions but please answer me

    Hi,
    I'm ending my website built with php+mysql.
    In a first moment I didn't want to use mysql but with the help of some
    manuals and 'how to' I have learned the most important instructions for
    my necessities.
    Only in few articles I have found annotations on the importance to close
    the access to database after every login and interrogation.
    In some cases I've found simply this line at the end of the php page:

    mysql_close($db);

    in other cases:

    mysql_free_result($xx);
    mysql_close($db);

    in other cases any worry to close the access!

    In my website every page connects to database, so please could you
    explain me the importance to close the database connection for each page?

    What are the correct istructions to follow at the end of a webpage to
    correctly disconnect from a database?

    I speak a little english, i hope that you understand what i need.
    Thanks.

    Marco (Italy)

    Mr.Orange Guest

  2. #2

    Default Re: simple questions but please answer me

    On 1 Feb, 10:53, "Mr.Orange" <it> wrote: 

    A web page does not connect to a database. It is the php script that
    is running on the server that does that.
    As long as you are not opening persistent connections, the connection
    will be closed when the current set of php scripts finishes executing,
    so you do not need to worry about either mysql_free_result($xx);
    mysql_close($db); at the end of the scripts.

    Captain Guest

  3. #3

    Default Re: simple questions but please answer me

    Thank you for the answer.
    My worry is that if I don't close the connection with an appropriate
    command and there are more users simultaneously connected, there can be
    a loss of performance or deceleration of the server.
    I hope that you understand what I want to say.

    Marco


     

    Mr.Orange Guest

  4. #4

    Default Re: simple questions but please answer me

    On 2 Feb, 11:51, "Mr.Orange" <it> wrote: 
    >
    > - Show quoted text -[/ref]

    Each "user" will be running a separate php session (not technically
    the correct term, but it'll do for now). Unless you have specifically
    opened persistent connections, each 'user' whole session (and their
    connections) will be shut down when apache (or whatever other server
    you are using) has finished delivering the page to the browser.

    Captain Guest

  5. #5

    Default Re: simple questions but please answer me

    Perfect, is the answer I need.
    Thanks and regards

    Marco
    Mr.Orange Guest

  6. #6

    Default Re: simple questions but please answer me

    Mr.Orange wrote: 

    Although as others have indicated it's not necessary to close the
    connection or free the result, I prefer to do it myself rather than let
    the PHP interpreter do it. It may be a while before the interpreter
    gets around to cleaning up after the script ends, especially in a
    heavily loaded server (cleanup is generally not as important as
    executing the scripts themselves).

    I go by the rule that as soon as I'm done with a result, I free it. As
    soon as I'm completely done with the connection on that page, I close it.

    I find it's just generally a good programming practice to clean up after
    myself rather than let the system do it for me.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  7. #7

    Default Re: simple questions but please answer me

    Hi Jerry,
    and about the cleanup are enough these two lines to the end of each php
    page:

    mysql_free_result($xx);
    mysql_close($db);


    or there's some other command to add?

    Thanks.
    Marco

     
    Mr.Orange Guest

  8. #8

    Default Re: simple questions but please answer me

    Mr.Orange wrote: [/ref]

    That's all you need. But I don't necessarily put them at the end of the
    page. For instance, I free a result as soon as I'm done with it. So
    once I fetch the data and use it, I free the result immediately. And
    once I've completed my last request to the database, I close the
    connection immediately.

    Freeing the result immediately is more important, IMHO. Often times
    I'll have a page which makes several separate requests to MySQL.
    Freeing a result as soon as I'm done with it means I'm not unnecessarily
    tying up MySQL and other system resources. It's also easier to remember
    to free it if you're doing it right where you 're using the result set.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  9. #9

    Default Re: simple questions but please answer me

    > Jerry Stuckle ha scritto: 

    ok, thanks to you too.
    ;-)

    Marco



    Mr.Orange Guest

Similar Threads

  1. Need Simple Answer to Simple Contribute/Firefox question
    By Adobe nickname in forum Macromedia Contribute General Discussion
    Replies: 2
    Last Post: February 13th, 06:59 PM
  2. Dutch answer to all programmers questions
    By Erik Visser in forum ASP.NET Web Services
    Replies: 0
    Last Post: May 20th, 09:22 AM
  3. hopefully simple answer
    By grover970 in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 16th, 01:57 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139