Re: PDO Prevent duplicate field names?
| From: | Jim Lucas | Date: | Mon, 02 Jul 2012 23:06:25 +0000 |
| Subject: | Re: PDO Prevent duplicate field names? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318380@lists.php.net to get a copy of this message | ||
On 07/02/2012 03:38 PM, Scott Baker wrote:
On 07/02/2012 03:34 PM, Matijn Woudt wrote:You could always do this. SELECT b.*, a.CustID FROM Customer a LEFT JOIN Sales B USING (CustID) WHERE a.CustID = 1234; -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/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.