Re: PDO Prevent duplicate field names?

From: Date: Mon, 02 Jul 2012 22:44:35 +0000
Subject: Re: PDO Prevent duplicate field names?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-318379@lists.php.net to get a copy of this message
On Tue, Jul 3, 2012 at 12:38 AM, Scott Baker <bakers@canbytel.com> wrote: > On 07/02/2012 03:34 PM, Matijn Woudt wrote: >> Why the #### would you want to return 2 columns with the same name? >> To be short, there's no such function, so you have to: >> 1) Rename one of the columns >> 2) or, use fetch_row with numerical indexes instead of fetch_assoc. > > My "real world" scenario was this > > SELECT a.CustID, b.* > FROM Customer a > LEFT JOIN Sales B USING (CustID) > WHERE a.CustID = 1234; > > In that case, there was a record in Customer, but not in Sales. Sales > returned CustID as NULL, which overwrote the one from Customer. > > It was my mistake, and the SQL was easily fixed. But it woulda been nice > to have PHP realize there was a dupe when it was building that array to > return to me. > Which makes me wonder, why are you returning a.CustID, if b includes CustID too and a.CustID == b.CustID? As to why there are no checks,.. I guess it's just that it's not a common error. And after all, all it does is set a value in an array twice, that doesn't result in warnings elsewhere (thank god ;)) - Matijn

« previous php.general (#318379) next »