Stale data when requerying MySQL w/PHP?

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

    Stale data when requerying MySQL w/PHP?

    I've got this weird problem. I'm connecting to MySQL via PHP,
    querying a particular table, closing the connection then parsing and
    displaying the results. I then modify the table but when I reload the
    PHP page, the output does not reflect this change.

    Viz:

    ----[SQL query]----
    mysqlselect * from users;
    +----------+
    | username |
    +----------+
    | jayds |
    +----------+

    ----[web page output]----
    Array ( [username] =jayds )

    ----[SQL query]----
    mysqlinsert into users values ("wes");
    Query OK, 1 row affected (0.00 sec)

    ----[reloaded web page output]----
    Array ( [username] =jayds )

    ....and a rechecking of the db reflects that "wes" IS, in fact, in the
    table.

    This is the code I'm using (minus the parts that parse and print the
    resource):

    ----[%begin%]----

    $conn = mysql_connect($ dbhost, $dbuser, $dbpass) or die ('Error
    connecting to mysql');

    mysql_select_db ('wes') or die('Could not select database');

    $query = "SELECT * FROM users";
    $resource = mysql_query($qu ery) or die('Query failed: ' .
    mysql_error());
    mysql_close($co nn);

    ----[%end%]----

    Any ideas on why I'm seeing stale data?

    Thanks much in advance!,
    Jason
  • Jerry Stuckle

    #2
    Re: Stale data when requerying MySQL w/PHP?

    bodhiSoma wrote:
    I've got this weird problem. I'm connecting to MySQL via PHP,
    querying a particular table, closing the connection then parsing and
    displaying the results. I then modify the table but when I reload the
    PHP page, the output does not reflect this change.
    >
    Viz:
    >
    ----[SQL query]----
    mysqlselect * from users;
    +----------+
    | username |
    +----------+
    | jayds |
    +----------+
    >
    ----[web page output]----
    Array ( [username] =jayds )
    >
    ----[SQL query]----
    mysqlinsert into users values ("wes");
    Query OK, 1 row affected (0.00 sec)
    >
    ----[reloaded web page output]----
    Array ( [username] =jayds )
    >
    ...and a rechecking of the db reflects that "wes" IS, in fact, in the
    table.
    >
    This is the code I'm using (minus the parts that parse and print the
    resource):
    >
    ----[%begin%]----
    >
    $conn = mysql_connect($ dbhost, $dbuser, $dbpass) or die ('Error
    connecting to mysql');
    >
    mysql_select_db ('wes') or die('Could not select database');
    >
    $query = "SELECT * FROM users";
    $resource = mysql_query($qu ery) or die('Query failed: ' .
    mysql_error());
    mysql_close($co nn);
    >
    ----[%end%]----
    >
    Any ideas on why I'm seeing stale data?
    >
    Thanks much in advance!,
    Jason
    >
    Caching - either by your browser or a system between your web server and
    your client?

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

    Comment

    • FutureShock

      #3
      Re: Stale data when requerying MySQL w/PHP?

      bodhiSoma wrote:
      I've got this weird problem. I'm connecting to MySQL via PHP,
      querying a particular table, closing the connection then parsing and
      displaying the results. I then modify the table but when I reload the
      PHP page, the output does not reflect this change.
      >
      Viz:
      >
      ----[SQL query]----
      mysqlselect * from users;
      +----------+
      | username |
      +----------+
      | jayds |
      +----------+
      >
      ----[web page output]----
      Array ( [username] =jayds )
      >
      ----[SQL query]----
      mysqlinsert into users values ("wes");
      Query OK, 1 row affected (0.00 sec)
      >
      ----[reloaded web page output]----
      Array ( [username] =jayds )
      >
      ...and a rechecking of the db reflects that "wes" IS, in fact, in the
      table.
      >
      This is the code I'm using (minus the parts that parse and print the
      resource):
      >
      ----[%begin%]----
      >
      $conn = mysql_connect($ dbhost, $dbuser, $dbpass) or die ('Error
      connecting to mysql');
      >
      mysql_select_db ('wes') or die('Could not select database');
      >
      $query = "SELECT * FROM users";
      $resource = mysql_query($qu ery) or die('Query failed: ' .
      mysql_error());
      mysql_close($co nn);
      >
      ----[%end%]----
      >
      Any ideas on why I'm seeing stale data?
      >
      Thanks much in advance!,
      Jason
      You performed an INSERT not an UPDATE.

      Could it be that you have both entires in your DB and only viewing one
      of them retrieved?

      The code you show is incomplete so its hard to tell.

      If you follow the code you have with:

      while($user = mysql_fetch_arr ay($resource)) {
      echo $user[username]."<br>";
      }

      Will it show the only one entry?

      Also not sure if this is in your actual code or just typed it wrong in
      here but:

      $resource = mysql_query($qu ery) or die('Query failed: ' .

      is missing the last )

      Scotty

      Comment

      • bodhiSoma

        #4
        Re: Stale data when requerying MySQL w/PHP?

        On Sep 28, 5:27 pm, FutureShock <futuresho...@a tt.netwrote:
        Could it be that you have both entires in your DB and only viewing one
        of them retrieved?
        That was precisely it. Thanks!!

        Jason

        Comment

        • FutureShock

          #5
          Re: Stale data when requerying MySQL w/PHP?

          bodhiSoma wrote:
          On Sep 28, 5:27 pm, FutureShock <futuresho...@a tt.netwrote:
          >
          >Could it be that you have both entires in your DB and only viewing one
          >of them retrieved?
          >
          That was precisely it. Thanks!!
          >
          Jason
          Glad to help. Don't be a stranger.

          Scotty

          Comment

          Working...