MySQL Connection Dies Randomly?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jake

    MySQL Connection Dies Randomly?

    I've spent the morning searching google groups without success, so I'm
    hoping someone has an idea of what's going on.

    I connect to a database like this:
    $catdb = @mysql_connect( "localhost" , "username", "password") ;
    @mysql_select_d b("mydatabase", $catdb);

    I have a problem on one script where I'll do a query using this connection,
    and it doesn't return anything. No results, no errors, nothing. But when
    I copy those two lines and paste them right above the query, it works fine.
    It's like the query dies between then and here.

    The first connection string isn't inside a function, but is the first two
    lines of the script. What would cause a connection to not respond? I'd at
    least expect a "$catdb is not a valid mysql link" or similar, but no error?
    What's going on?
  • Senator Jay Billington Bulworth

    #2
    Re: MySQL Connection Dies Randomly?

    In article <Xns93FD7CADFB0 30nonenonecom@2 4.28.95.190>,
    Jake <jt@nospamforme thanks.com> wrote:
    [color=blue]
    > The first connection string isn't inside a function, but is the first two
    > lines of the script. What would cause a connection to not respond?[/color]

    Is the query itself, which tries to use the $catdb resource handle,
    inside of a function? If so, you need to tell the function that $catdb
    exists in the global scope. Try adding:

    global $catdb;

    ...as the first line of the function.
    [color=blue]
    > I'd at
    > least expect a "$catdb is not a valid mysql link" or similar, but no error?
    > What's going on?[/color]

    The @ sign is used to suppress any errors that result from a function
    call. Try removing the @ signs from mysql_connect() and
    mysql_select_db () and see if you get any info, otherwise, stick an

    echo mysql_error();

    ...between each step of the process to see if MySQL is complaining about
    something.

    hth

    --
    Bulworth : funha@fung.arg | My email address is ROT13 encoded, decode to mail
    --------------------------|--------------------------------------------------
    <http://www.phplabs.com/> | PHP scripts and thousands of webmaster resources!

    Comment

    Working...