php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48151 Joining key returns as blank when key is used in OUT LEFT JOIN
Submitted: 2009-05-05 07:26 UTC Modified: 2009-05-14 01:00 UTC
From: mail at danhofnann dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-05-05 07:26 UTC] mail at danhofnann dot com
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"
            ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-06 21:32 UTC] jani@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2009-05-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 20:01:31 2024 UTC