Warning: mysql_query(): 4 is not a valid MySQL-Link resource

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

    Warning: mysql_query(): 4 is not a valid MySQL-Link resource

    Hi,

    I got this warning:
    mysql_query(): 4 is not a valid MySQL-Link resource.

    The line which cause this warning is:
    mysql_query("in sert into $tablename (id,priority) values('$id',
    '0.00')", $link2);

    As far as understand the problem is that $link2 is "not a valid MySQL-
    Link resource".
    I specify $link2 in this way:
    $link2 = mysql_connect( "localhost","lo ctopu_user","us erpsw" );

    And it seems to be valid to some place in my code (because I
    successfully use it with different mysql_queries). The problem appears
    after I call one function. After that $link2 is not a valid MySQL-Link
    resource anymore. In the function I open and close another connection
    to the MySQL server. But doing that I use another name for the link
    resource. Moreover, I think, the link resource used in a function
    should is treated a local variable, so it should be invisible from the
    outside of the function.

    So, what can it be? How a function can destroy the link resource of
    the program which calls the function?

    Thank you.
  • Jerry Stuckle

    #2
    Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

    Kurda Yon wrote:
    Hi,
    >
    I got this warning:
    mysql_query(): 4 is not a valid MySQL-Link resource.
    >
    The line which cause this warning is:
    mysql_query("in sert into $tablename (id,priority) values('$id',
    '0.00')", $link2);
    >
    As far as understand the problem is that $link2 is "not a valid MySQL-
    Link resource".
    I specify $link2 in this way:
    $link2 = mysql_connect( "localhost","lo ctopu_user","us erpsw" );
    >
    And it seems to be valid to some place in my code (because I
    successfully use it with different mysql_queries). The problem appears
    after I call one function. After that $link2 is not a valid MySQL-Link
    resource anymore. In the function I open and close another connection
    to the MySQL server. But doing that I use another name for the link
    resource. Moreover, I think, the link resource used in a function
    should is treated a local variable, so it should be invisible from the
    outside of the function.
    >
    So, what can it be? How a function can destroy the link resource of
    the program which calls the function?
    >
    Thank you.
    >
    It's hard to tell without seeing the entire code.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • ZeldorBlat

      #3
      Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

      On Feb 7, 10:04 pm, Kurda Yon <kurda...@yahoo .comwrote:
      Hi,
      >
      I got this warning:
      mysql_query(): 4 is not a valid MySQL-Link resource.
      >
      The line which cause this warning is:
      mysql_query("in sert into $tablename (id,priority) values('$id',
      '0.00')", $link2);
      >
      As far as understand the problem is that $link2 is "not a valid MySQL-
      Link resource".
      I specify $link2 in this way:
      $link2 = mysql_connect( "localhost","lo ctopu_user","us erpsw" );
      >
      And it seems to be valid to some place in my code (because I
      successfully use it with different mysql_queries). The problem appears
      after I call one function. After that $link2 is not a valid MySQL-Link
      resource anymore. In the function I open and close another connection
      to the MySQL server. But doing that I use another name for the link
      resource. Moreover, I think, the link resource used in a function
      should is treated a local variable, so it should be invisible from the
      outside of the function.
      >
      So, what can it be? How a function can destroy the link resource of
      the program which calls the function?
      >
      Thank you.
      In the manual under mysql_connect() is this note:

      "If a second call is made to mysql_connect() with the same arguments,
      no new link will be established, but instead, the link identifier of
      the already opened link will be returned. The new_link parameter
      modifies this behavior and makes mysql_connect() always open a new
      link, even if mysql_connect() was called before with the same
      parameters. In SQL safe mode, this parameter is ignored."

      So, when you open the second link, you're really just getting a copy
      of the first one. Thus, when you close it, you've closed the
      connection in both places.

      Some solutions:

      1. Specify the new_link parameter when calling mysql_connect() .
      2. Don't explicitly close the connection -- you typically don't need
      to anyway.
      3. Use singletons.

      Comment

      • Jerry Stuckle

        #4
        Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

        ZeldorBlat wrote:
        On Feb 7, 10:04 pm, Kurda Yon <kurda...@yahoo .comwrote:
        >Hi,
        >>
        >I got this warning:
        >mysql_query( ): 4 is not a valid MySQL-Link resource.
        >>
        >The line which cause this warning is:
        >mysql_query("i nsert into $tablename (id,priority) values('$id',
        >'0.00')", $link2);
        >>
        >As far as understand the problem is that $link2 is "not a valid MySQL-
        >Link resource".
        >I specify $link2 in this way:
        >$link2 = mysql_connect( "localhost","lo ctopu_user","us erpsw" );
        >>
        >And it seems to be valid to some place in my code (because I
        >successfully use it with different mysql_queries). The problem appears
        >after I call one function. After that $link2 is not a valid MySQL-Link
        >resource anymore. In the function I open and close another connection
        >to the MySQL server. But doing that I use another name for the link
        >resource. Moreover, I think, the link resource used in a function
        >should is treated a local variable, so it should be invisible from the
        >outside of the function.
        >>
        >So, what can it be? How a function can destroy the link resource of
        >the program which calls the function?
        >>
        >Thank you.
        >
        In the manual under mysql_connect() is this note:
        >
        "If a second call is made to mysql_connect() with the same arguments,
        no new link will be established, but instead, the link identifier of
        the already opened link will be returned. The new_link parameter
        modifies this behavior and makes mysql_connect() always open a new
        link, even if mysql_connect() was called before with the same
        parameters. In SQL safe mode, this parameter is ignored."
        >
        So, when you open the second link, you're really just getting a copy
        of the first one. Thus, when you close it, you've closed the
        connection in both places.
        >
        I saw that, but I'm not sure if that's what he's doing or not - hence
        the request for the code.
        Some solutions:
        >
        1. Specify the new_link parameter when calling mysql_connect() .
        True.
        2. Don't explicitly close the connection -- you typically don't need
        to anyway.
        Not true. You should always close connections when completely through
        with them. It's good programming practice, if nothing else. But it
        also means you're releasing system resources you no longer need, making
        them available to others.
        3. Use singletons.
        >
        The best way, IMHO.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • AnrDaemon

          #5
          Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

          Greetings, Jerry Stuckle.
          In reply to Your message dated Friday, February 8, 2008, 15:26:59,
          >2. Don't explicitly close the connection -- you typically don't need
          >to anyway.
          Not true. You should always close connections when completely through
          with them. It's good programming practice, if nothing else. But it
          also means you're releasing system resources you no longer need, making
          them available to others.
          Looks You have never used PHP as a module...
          And database connection will be closed anyway when there are no other scripts
          using it.


          --
          Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

          Comment

          • Rik Wasmus

            #6
            Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

            On Thu, 14 Feb 2008 21:27:56 +0100, AnrDaemon <anrdaemon@free mail.ru>
            wrote:
            Greetings, Jerry Stuckle.
            In reply to Your message dated Friday, February 8, 2008, 15:26:59,
            >
            >>2. Don't explicitly close the connection -- you typically don't need
            >>to anyway.
            >
            >Not true. You should always close connections when completely through
            >with them. It's good programming practice, if nothing else. But it
            >also means you're releasing system resources you no longer need, making
            >them available to others.
            >
            Looks You have never used PHP as a module...
            And database connection will be closed anyway when there are no other
            scripts
            using it.
            If you don't, it will be open for the remainder of the script. On a high
            traffic site, and a heavy page, hogging the connection for 0.5 seconds
            while another script might need it is not a good thing... Maximum
            connections to a database are usually limited.
            --
            Rik Wasmus

            Comment

            • Jerry Stuckle

              #7
              Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

              AnrDaemon wrote:
              Greetings, Jerry Stuckle.
              In reply to Your message dated Friday, February 8, 2008, 15:26:59,
              >
              >>2. Don't explicitly close the connection -- you typically don't need
              >>to anyway.
              >
              >Not true. You should always close connections when completely through
              >with them. It's good programming practice, if nothing else. But it
              >also means you're releasing system resources you no longer need, making
              >them available to others.
              >
              Looks You have never used PHP as a module...
              And database connection will be closed anyway when there are no other scripts
              using it.
              >
              >
              I always use PHP as a module.

              But it's still a good idea to clean up after yourself. Don't depend on
              the garbage collector to do it for you. It's sloppy programming, and
              the mark of a lazy programmer.

              For instance, it may be a while before the gc gets around to closing the
              connection, especially on a busy system. The result is way more open
              connections than you need.




              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • AnrDaemon

                #8
                Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

                Greetings, Rik Wasmus.
                In reply to Your message dated Thursday, February 14, 2008, 23:46:14,
                >>>2. Don't explicitly close the connection -- you typically don't need
                >>>to anyway.
                >>
                >>Not true. You should always close connections when completely through
                >>with them. It's good programming practice, if nothing else. But it
                >>also means you're releasing system resources you no longer need, making
                >>them available to others.
                >>
                >Looks You have never used PHP as a module...
                >And database connection will be closed anyway when there are no other
                >scripts
                >using it.
                If you don't, it will be open for the remainder of the script. On a high
                traffic site, and a heavy page, hogging the connection for 0.5 seconds
                while another script might need it is not a good thing... Maximum
                connections to a database are usually limited.
                Sorry if I misunderstood developer's manual, but it said if I use persistent
                connections to database (while using PHP as module, of course), database
                connection will never be closed even if I explicitly call *_close, while there
                are more than one script using this database connection.


                --
                Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

                Comment

                • Jerry Stuckle

                  #9
                  Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

                  AnrDaemon wrote:
                  Greetings, Rik Wasmus.
                  In reply to Your message dated Thursday, February 14, 2008, 23:46:14,
                  >
                  >>>>2. Don't explicitly close the connection -- you typically don't need
                  >>>>to anyway.
                  >>>Not true. You should always close connections when completely through
                  >>>with them. It's good programming practice, if nothing else. But it
                  >>>also means you're releasing system resources you no longer need, making
                  >>>them available to others.
                  >>Looks You have never used PHP as a module...
                  >>And database connection will be closed anyway when there are no other
                  >>scripts
                  >>using it.
                  >
                  >If you don't, it will be open for the remainder of the script. On a high
                  >traffic site, and a heavy page, hogging the connection for 0.5 seconds
                  >while another script might need it is not a good thing... Maximum
                  >connections to a database are usually limited.
                  >
                  Sorry if I misunderstood developer's manual, but it said if I use persistent
                  connections to database (while using PHP as module, of course), database
                  connection will never be closed even if I explicitly call *_close, while there
                  are more than one script using this database connection.
                  >
                  >
                  That's your first mistake. You shouldn't be using persistent
                  connections - they can decrease performance of your server.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • AnrDaemon

                    #10
                    Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

                    Greetings, Jerry Stuckle.
                    In reply to Your message dated Tuesday, February 19, 2008, 14:57:12,
                    >>>>>2. Don't explicitly close the connection -- you typically don't need
                    >>>>>to anyway.
                    >>>>Not true. You should always close connections when completely through
                    >>>>with them. It's good programming practice, if nothing else. But it
                    >>>>also means you're releasing system resources you no longer need, making
                    >>>>them available to others.
                    >>>Looks You have never used PHP as a module...
                    >>>And database connection will be closed anyway when there are no other
                    >>>scripts
                    >>>using it.
                    >>
                    >>If you don't, it will be open for the remainder of the script. On a high
                    >>traffic site, and a heavy page, hogging the connection for 0.5 seconds
                    >>while another script might need it is not a good thing... Maximum
                    >>connections to a database are usually limited.
                    >>
                    >Sorry if I misunderstood developer's manual, but it said if I use persistent
                    >connections to database (while using PHP as module, of course), database
                    >connection will never be closed even if I explicitly call *_close, while there
                    >are more than one script using this database connection.
                    That's your first mistake. You shouldn't be using persistent
                    connections - they can decrease performance of your server.
                    It is not a mistake, it's made to work that way and there are no perfomance
                    issues with that. Please stop posting such comments.


                    --
                    Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

                      AnrDaemon wrote:
                      Greetings, Jerry Stuckle.
                      In reply to Your message dated Tuesday, February 19, 2008, 14:57:12,
                      >
                      >>>>>>2. Don't explicitly close the connection -- you typically don't need
                      >>>>>>to anyway.
                      >>>>>Not true. You should always close connections when completely through
                      >>>>>with them. It's good programming practice, if nothing else. But it
                      >>>>>also means you're releasing system resources you no longer need, making
                      >>>>>them available to others.
                      >>>>Looks You have never used PHP as a module...
                      >>>>And database connection will be closed anyway when there are no other
                      >>>>scripts
                      >>>>using it.
                      >>>If you don't, it will be open for the remainder of the script. On a high
                      >>>traffic site, and a heavy page, hogging the connection for 0.5 seconds
                      >>>while another script might need it is not a good thing... Maximum
                      >>>connection s to a database are usually limited.
                      >>Sorry if I misunderstood developer's manual, but it said if I use persistent
                      >>connections to database (while using PHP as module, of course), database
                      >>connection will never be closed even if I explicitly call *_close, while there
                      >>are more than one script using this database connection.
                      >
                      >That's your first mistake. You shouldn't be using persistent
                      >connections - they can decrease performance of your server.
                      >
                      It is not a mistake, it's made to work that way and there are no perfomance
                      issues with that. Please stop posting such comments.
                      >
                      >
                      You should really learn how persistent connections can hurt server
                      performance.

                      Please stop encouraging such poor programming techniques.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Warning: mysql_query(): 4 is not a valid MySQL-Link resource

                        AnrDaemon wrote:
                        Greetings, Jerry Stuckle.
                        In reply to Your message dated Tuesday, February 19, 2008, 14:57:12,
                        >
                        >>>>>>2. Don't explicitly close the connection -- you typically don't need
                        >>>>>>to anyway.
                        >>>>>Not true. You should always close connections when completely through
                        >>>>>with them. It's good programming practice, if nothing else. But it
                        >>>>>also means you're releasing system resources you no longer need, making
                        >>>>>them available to others.
                        >>>>Looks You have never used PHP as a module...
                        >>>>And database connection will be closed anyway when there are no other
                        >>>>scripts
                        >>>>using it.
                        >>>If you don't, it will be open for the remainder of the script. On a high
                        >>>traffic site, and a heavy page, hogging the connection for 0.5 seconds
                        >>>while another script might need it is not a good thing... Maximum
                        >>>connection s to a database are usually limited.
                        >>Sorry if I misunderstood developer's manual, but it said if I use persistent
                        >>connections to database (while using PHP as module, of course), database
                        >>connection will never be closed even if I explicitly call *_close, while there
                        >>are more than one script using this database connection.
                        >
                        >That's your first mistake. You shouldn't be using persistent
                        >connections - they can decrease performance of your server.
                        >
                        It is not a mistake, it's made to work that way and there are no perfomance
                        issues with that. Please stop posting such comments.
                        >
                        >
                        Oh, and one other thing - if you want to know why, ask in
                        comp.databases. mysql. They'll give you a lot of information.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        Working...