|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-05-06 21:32 UTC] jani@php.net
[2009-05-14 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 10 18:00:02 2025 UTC |
Description: ------------ If you do an OUTER LEFT JOIN and set PDO FetchALL to PDO::FETCH_ASSOC, any primary keys you used in the OUTER LEFT JOIN will be set to a blank if there are no records returned in the JOIN. If we are joining using a field called "product_id" from a product table to an image table using an outer left join, and no records exist for that "product_id" in the image table, the product id comes back as blank in the resulting array Reproduce code: --------------- //query the product table and join to the image table and return any images, if we have any, for each product. Assume the image table contains no records $sql = "SELECT * FROM product, image LEFT OUTER JOIN image ON (product.product_id = image.product_id)"; $array = $stmt->fetchAll(PDO::FETCH_ASSOC); print_r($array); ?> Expected result: ---------------- Array ( [0] => Array ( [product_id] => 16 [notes] => "this product..." [brand] => "Best Yet" ... Actual result: -------------- Array ( [0] => Array ( [product_id] => [notes] => "this product..." [brand] => "Best Yet" ...