Re: PHP 4.0 and Postgres Update problems

From: Date: Thu, 15 Jun 2000 07:35:36 +0000
Subject: Re: PHP 4.0 and Postgres Update problems
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-437@lists.php.net to get a copy of this message
Hi William-- Is there really a period at the very end of the SQL statement? I'm unsure if it would be a major problem, but perhaps there are conversion problems between a floating point (1.) number and an integer (1) number when the WHERE clause is attempting to match which records will be updated. After all, the symptoms you're describing scream that the WHERE clause is being evaluated incorrectly and is somehow matching all the records. So when you cut & paste the SQL into psql, you obviously have to add the semicolon to the end of the statement...at that time are you also deleting the period? I wish I was at my office...I'd whip up a quick test to see what effect a trailing period would have on a WHERE clause that's supposedly selecting based upon an integer value. Since your SQL is grammatically correct, I can see no other reason the WHERE clause would be matching all the records. Ummmm, that is unless uid is a text field instead of a numeric type, in which case your WHERE clause may be actually saying (in english), "WHERE uid is true." In that case any value in uid would cause it to be true. If that period in your post was only there because you typed it in and it's not really there in the SQL, then I cannot find anything wrong with your SQL. Perhaps if you terminated the SQL with a semicolon? You really shouldn't have to when running through PHP (which simply uses libpq to actually do the query)...but it couldn't hurt. So I guess to summarize: o If your uid field is an integer and there really is a period there at the end of your UPDATE, get rid of the period o If your uid field is text/char, put apostrophes around the uid value you're trying to match; the one (1) in the example would become '1' o Try terminating with a semicolon (but this is a long shot) Doug At 10:18 PM 6/14/00 -0400, William Moore wrote: >Hello, I was wondering if someone could help me out with a slight problem >that I am having with updating a table in a php script. Basiclly I have a >class methood (update) that cycles through $HTTP_POST_VARS, and compares >that array with the contents of the object created from that class. >Depending on what has changed it genorates a SQL statement to update only >those fields. Everything works to the point of actually performing the >query. When I print the SQL statement out to verify that it is correct, >it is and I come up with something along the lines of > >UPDATE user_table SET name='blahblah', phone='blahblah' WHERE uid=1. > >If I copy/paste this directly to psql it works just like you would expect, >however when running this through pg_exec( ), it updates ALL rows in the >table to these values. Any ideas, or has anybody seen this before? I've >read over FAQ's, tutorials, readme's but can't find anything to figure out >why this would happen. >

« previous php.db (#437) next »