Does this PHP code look OK?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steen2
    Confirmed User
    • Feb 2004
    • 7662

    #1

    Does this PHP code look OK?

    PHP Code:
        function mysqlconn() {
             $user = "DB_DB";
             $pass = "pass";
             $db = "DB_DB";
             $newconnect = mysql_pconnect(localhost, $user,$pass) or die(mysql_error());
             mysql_select_db($db) or die(mysql_error());
             if(mysql_error()) { echo mysql_error(); }
        } 
    
    It's causing this error in my error logs and looks to be hurting the server: PHP Warning: mysql_pconnect(): Link to server lost, unable to reconnect in ...

    The line the error references is
    $user = "DB_DB";

    But I included the lines around it for better insight.
    ICQ: 2262.73945
  • ssp
    Confirmed User
    • Jan 2005
    • 7990

    #2
    Have you tried using all lower cases in your username?

    Comment

    • Steen2
      Confirmed User
      • Feb 2004
      • 7662

      #3
      Originally posted by ssp
      Have you tried using all lower cases in your username?
      Sorry?

      "DB_DB" is to edit out information that's "sensitive".
      ICQ: 2262.73945

      Comment

      • ssp
        Confirmed User
        • Jan 2005
        • 7990

        #4
        Perhaps it's because there is a space in this line:

        mysql_pconnect(localhost, $user,$pass)

        Comment

        • Calvinguy
          Confirmed User
          • Oct 2002
          • 1752

          #5
          Try to use single qoutes ' rather then doubleqoutes "


          or put qoutes around localhost also...

          Comment

          • Steen2
            Confirmed User
            • Feb 2004
            • 7662

            #6
            Originally posted by ssp
            Perhaps it's because there is a space in this line:

            mysql_pconnect(localhost, $user,$pass)
            Try to use single qoutes ' rather then doubleqoutes "


            or put qoutes around localhost also...
            Thanks, but would this crash the server's mysql?
            ICQ: 2262.73945

            Comment

            • Serge Litehead
              Confirmed User
              • Dec 2002
              • 5190

              #7
              put localhost in single qoutes
              whitespace such as spaces, tabs, etc in code is ignored

              seems there s a prob with connection rather than anything else at this point
              i've never used mysql_pconnect, see if mysql_connect works better for you.

              Comment

              • Nysus
                Confirmed User
                • Aug 2001
                • 7817

                #8
                Hope you're putting that function in an include file as opposed to on a page, or have multiple DBs at different locations to use... you only need to connect to a mySQL server once each load.

                Matt
                What name is pr0 / Untouched Markets using these days? Untouched Markets - pr0 - Refund My Money Now

                Someone owes me $2,000 because they didn't do any work that was paid for *pointing at pr0 / William / UntouchedMarkets*

                See http://www.gfy.com/showthread.php?p=16744521 and for more detailed see http://www.gfy.com/showthread.php?t=948645

                Comment

                • who
                  So Fucking Banned
                  • Aug 2003
                  • 19593

                  #9
                  Is your username the same as the database name?

                  Comment

                  • Serge Litehead
                    Confirmed User
                    • Dec 2002
                    • 5190

                    #10
                    here is a good sample for you from php manual:

                    Code:
                    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die (mysql_error());
                    db_selected = mysql_select_db('db_name', $link) or die (mysql_error());
                    or die() is not recommended for use in live production.

                    Comment

                    • Serge Litehead
                      Confirmed User
                      • Dec 2002
                      • 5190

                      #11
                      err in above post

                      db_selected = $db_selected

                      Comment

                      Working...