Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:23:00+00:00 2026-05-27T03:23:00+00:00

I have a function to retrieve a single row of data representing a sales

  • 0

I have a function to retrieve a single row of data representing a sales report for a store on a specific date. I’m using similar methodology to retrieve data throughout the same class and application and have never run into this problem. My function (and fetch()) are returning false, while the execute() is returning true.

When I run the same query in TOAD from the SQL editor, I’m getting a row of data back as expected.

Why is fetch() failing? Note: I also tried fetchAll() which is returning an empty set. I’ve also tried not using bound parameters, but that doesn’t work either.

Here’s the code:

    public function getFullReport($store_id, $date)
    {
        $pdo = $this->application->database()->PDO();
        $user_id = $this->application->session()->user_id();

        $query = <<<SQL
SELECT sales_reports.*,
       labor2.hours AS labor_am,
       labor3.hours AS labor_wa,
       labor4.hours AS labor_associate,
       labor5.hours AS labor_kitchen,
       labor6.hours AS labor_training
  FROM sales_reports
       JOIN labor_reports AS labor2
          ON     sales_reports.store_id = labor2.store_id
             AND sales_reports.date = labor2.date
             AND labor2.labor_type_id = 2
       JOIN labor_reports AS labor3
          ON     sales_reports.store_id = labor3.store_id
             AND sales_reports.date = labor3.date
             AND labor3.labor_type_id = 3
       JOIN labor_reports AS labor4
          ON     sales_reports.store_id = labor4.store_id
             AND sales_reports.date = labor4.date
             AND labor4.labor_type_id = 4
       JOIN labor_reports AS labor5
          ON     sales_reports.store_id = labor5.store_id
             AND sales_reports.date = labor5.date
             AND labor5.labor_type_id = 5
       JOIN labor_reports AS labor6
          ON     sales_reports.store_id = labor6.store_id
             AND sales_reports.date = labor6.date
             AND labor6.labor_type_id = 6
       JOIN user_store_permissions
          ON sales_reports.store_id = user_store_permissions.store_id
 WHERE     sales_reports.store_id = :store_id
       AND sales_reports.date = :date
       AND user_store_permissions.user_id = :user_id
 LIMIT 1
SQL;

        $statement = $pdo->prepare($query);
        $statement->bindParam(':store_id', $store_id);
        $statement->bindParam(':date', $date);
        $statement->bindParam(':user_id', $user_id);

        $statement->execute();

        return $statement->fetch(PDO::FETCH_ASSOC);
    }

UPDATE

It seems that the labor JOINs are failing for some reason. When I use LEFT JOIN it returns a row – with all of the labor values as null. However, I’m not seeing this result in Toad for MySQL, which performs both the LEFT JOIN and JOIN version of the query properly and returns the full row.

So the new question is, why are my JOINs not working in my PHP PDO code but they are working on the same data, with the same parameters when running the SQL in Toad?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:23:00+00:00Added an answer on May 27, 2026 at 3:23 am

    Sorry – I resolved this quite a long time ago and forgot to answer my own question as Relequestual recommended.

    I believe the issue was that I was running the Toad SQL queries on my remote MySQL server whereas the PHP PDO statements were running off of my local MySQL server. A silly, typical headscratcher when you’ve been staring at the screen too long!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which has a function to retrieve children elements from a
So I have function that formats a date to coerce to given enum DateType{CURRENT,
I have an Oracle 10g function, named 'F_SMART_DATE()', that returns a scalar DATE. It
I have a flash application which uses a single php file to retrieve records
i have a function which retrieves values from a webservice , then loops through
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I have function getCartItems in cart.js and I want to call that function in
If I have function names stored as strings in a Hashtable. Is there a
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.