By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

Stale data when requerying MySQL w/PHP?

P: n/a
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($query) or die('Query failed: ' .
mysql_error());
mysql_close($conn);

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

Any ideas on why I'm seeing stale data?

Thanks much in advance!,
Jason
Sep 28 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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($query) or die('Query failed: ' .
mysql_error());
mysql_close($conn);

----[%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.
js*******@attglobal.net
==================

Sep 28 '08 #2

P: n/a
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($query) or die('Query failed: ' .
mysql_error());
mysql_close($conn);

----[%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_array($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($query) or die('Query failed: ' .

is missing the last )

Scotty

Sep 28 '08 #3

P: n/a
On Sep 28, 5:27*pm, FutureShock <futuresho...@att.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
Sep 29 '08 #4

P: n/a
bodhiSoma wrote:
On Sep 28, 5:27 pm, FutureShock <futuresho...@att.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
Sep 29 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.