SearchSearch   

Stale data when requerying MySQL w/PHP?

 
   Webmaster Forums (Home) -> PHP MySQL RSS
Next:  Job Posting - West Michigan (Grand Rapids, MI) US..  
Author Message
bodhiSoma

External


Since: Sep 26, 2008
Posts: 6



(Msg. 1) Posted: Sun Sep 28, 2008 11:41 am
Post subject: Stale data when requerying MySQL w/PHP?
Archived from groups: alt>php>sql, others (more info?)

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]----
mysql> select * from users;
+----------+
| username |
+----------+
| jayds |
+----------+

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

----[SQL query]----
mysql> insert 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
Back to top
FutureShock

External


Since: Sep 28, 2008
Posts: 2



(Msg. 2) Posted: Sun Sep 28, 2008 2:27 pm
Post subject: Re: Stale data when requerying MySQL w/PHP?
Archived from groups: per prev. post (more info?)

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]----
> mysql> select * from users;
> +----------+
> | username |
> +----------+
> | jayds |
> +----------+
>
> ----[web page output]----
> Array ( [username] => jayds )
>
> ----[SQL query]----
> mysql> insert 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
Back to top
Jerry Stuckle

External


Since: Jul 08, 2004
Posts: 3787



(Msg. 3) Posted: Sun Sep 28, 2008 3:46 pm
Post subject: Re: Stale data when requerying MySQL w/PHP?
Archived from groups: per prev. post (more info?)

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]----
> mysql> select * from users;
> +----------+
> | username |
> +----------+
> | jayds |
> +----------+
>
> ----[web page output]----
> Array ( [username] => jayds )
>
> ----[SQL query]----
> mysql> insert 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.
jstucklex.DeleteThis@attglobal.net
==================
Back to top
bodhiSoma

External


Since: Sep 26, 2008
Posts: 6



(Msg. 4) Posted: Sun Sep 28, 2008 11:05 pm
Post subject: Re: Stale data when requerying MySQL w/PHP?
Archived from groups: per prev. post (more info?)

On Sep 28, 5:27 pm, FutureShock <futuresho....TakeThisOut@att.net> wrote:

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

That was precisely it. Thanks!!

Jason
Back to top
FutureShock

External


Since: Sep 28, 2008
Posts: 2



(Msg. 5) Posted: Mon Sep 29, 2008 5:42 am
Post subject: Re: Stale data when requerying MySQL w/PHP?
Archived from groups: per prev. post (more info?)

bodhiSoma wrote:
> On Sep 28, 5:27 pm, FutureShock <futuresho... DeleteThis @att.net> wrote:
>
>> 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
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> PHP MySQL
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum