Hi,

I have mysql_connection issue on my server. I don't know what reason for this error. I have one table that having so many records. I am fetching selected field from this table(ex result table) . I have optimized my query , no loop used here,I am thinking may be this can be one reason in connection .Please give me idea what can be solution for this issue . My error on page is:

Warning: mysql_connect() [function.mysql-connect]: Too many connections in (path of connection file)

Thanks,
Rhythm

    Does your script call mysql_connect more than once? Without any source code examples, it would be hard to tell. Your script should connect once (and exactly once) and run all queries using that one single connection.

    If your script does connect only once, then it sounds like your site is very busy -- or your server's mysql-related configuration doesn't permit very many connections.

      sneakyimp;10993765 wrote:

      Your script should connect once (and exactly once) and run all queries using that one single connection.

      ...unless there are significant delays between two points where MySQL interaction is needed, in which case it would be more beneficial to close the otherwise idle connection (which, idle or not, is still going to consume a connection resource).

        Ah yes BG you are again properly thorough. I was sort of assuming a standard page that loads quickly and doesn't run off and do something time-consuming that is not related to db usage (e.g., parse large files or manipulate an image or something).

        If your script opened a db connection and is going to be busy for awhile doing something that is NOT db-related, you should close/disconnect from the db to free it up for use by another page request.

          Hi All

          Thanks for your reply. I have used a single file that contains connection using mysql_connect() and mysql_select_db() for select data base. I have included this file on my header and also i am using one class file for all queries i also included my connection file in class file.What i am doing worng ?

          Thanks,
          Rhythm

            if you [man]include[/man] a file twice rather than using [man]include_once[/man] then the file's contents will be re-evaluated again. It may well be that you are connecting more than once in your script. Alternatively, if your server is very busy, then you may be able to tweak your mysql configuration to permit more connections at the risk of over-burdening your server.

            I recommend you try and figure out how many times your script calls mysql_connect and then try to reduce that to just once.

              Hi sneakyimp

              I am using required_once to include file in another file.I think this is correct.Is It ?
              I don't have any issue on local machine but my server is very slow nothing happening on it only displaying error.

                Do you think this is my sql query issue that taking time to execute ?

                  It's really impossible for us to say without you giving us specific details of what your code is doing. All we can do is offer general advice.

                    Rhythm purohit;10993858 wrote:

                    I am using required_once to include file in another file.I think this is correct.Is It ?
                    I don't have any issue on local machine but my server is very slow nothing happening on it only displaying error.

                    That sounds very different than "it's taking a long time". Code should not produce any errors when it runs. Weedpacket is right. We'll need to see code and the exact error message to give any more specific advice.

                      Hi
                      Yes You are right. My code in connection file is
                      $database = mysql_connect('localhost', 'username', 'password');

                      // DATABASE SELECTION
                      mysql_select_db('DBNAME',$database) or die ('database access error'.mysql_error());

                      Error was
                      Warning: mysql_connect() [function.mysql-connect]: Too many connections in (path of connection file)

                      Now i used mysql_pconnect() at the place of mysql_connect() and restart server so i have not got any error.

                      it is working fine for now. Is it good for future?

                      Thanks
                      Rhythm

                        Write a Reply...