Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Stale data when requerying MySQL w/PHP?

 
   Database Help (Home) -> PHP SQL RSS
Next:  foto  
Author Message
bodhiSoma

External


Since: Sep 28, 2008
Posts: 2



(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

 >> Stay informed about: Stale data when requerying MySQL w/PHP? 
Back to top
Login to vote
FutureShock

External


Since: Sep 28, 2008
Posts: 33



(Msg. 2) Posted: Sun Sep 28, 2008 2:27 pm
Post subject: Re: Stale data when requerying MySQL w/PHP? [Login to view extended thread Info.]
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

 >> Stay informed about: Stale data when requerying MySQL w/PHP? 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 3530



(Msg. 3) Posted: Sun Sep 28, 2008 3:46 pm
Post subject: Re: Stale data when requerying MySQL w/PHP? [Login to view extended thread Info.]
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
==================
 >> Stay informed about: Stale data when requerying MySQL w/PHP? 
Back to top
Login to vote
bodhiSoma

External


Since: Sep 28, 2008
Posts: 2



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

On Sep 28, 5:27 pm, FutureShock <futuresho... RemoveThis @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
 >> Stay informed about: Stale data when requerying MySQL w/PHP? 
Back to top
Login to vote
FutureShock

External


Since: Sep 28, 2008
Posts: 33



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

bodhiSoma wrote:
> 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

Glad to help. Don't be a stranger.

Scotty
 >> Stay informed about: Stale data when requerying MySQL w/PHP? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
MySQL - question about displaying data - I am working an some pages that have database content on them. I'm sorry that I don't have any versions of it online yet, but it isn't hard to explain. The site lists restaurants with contact information. All of the information is kept in a MySQL..

php + MySQL problems - I'm trying to get php + MySQL running on my web server. I tested the setup on an old RH8 server install that I was going to upgrade; everything worked fine. So I wiped out the old RedHat, installed Fedora Core 2, and repeated the installation. No dice...

Accounts in Mysql - Hello, Learning about Mysql Accounts, there is something I like to ask for. I have made some database tests as root mysql with [gastonv@telenetPC ~]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL....

php and mySql - I get an error message while trying to follow these procedures: http://www.howtoforge.com/intrusion-...on-ubuntu-7.10 Here is the error: Fatal error: Call to undefined function mysql_connect() in /var/www/adodb5/drivers/adodb-mysql.inc.php on line 363..

[MySQL] hierachy problem ... - Hello, I have a table which have these fields: - id - idParent - label I would like to display each field and his children but each parent may have no child. Example: A AA AB AC B C CA CB .... I can't write the request, could you help me?....
   Database Help (Home) -> PHP SQL All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can 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



[ Contact us | Terms of Service/Privacy Policy ]