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 8582585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:19:43+00:00 2026-06-11T21:19:43+00:00

This is so baffling I MUST be missing something simple. I have a query

  • 0

This is so baffling I MUST be missing something simple. I have a query that checks to see if the transaction I’m inserting already exists in order to prevent duplicates. Here’s the code:

function isaDupe($portableDB, $transactArray)
{
    $ref = $transactArray["reference"];
    $date = $transactArray["qdate"];
    $time =  $transactArray["time"];

  //prints the query so I can run by hand to test
    print "SELECT `counter` FROM transactions WHERE (`reference` = '$ref' AND `qdate` = '$date' AND `time` = '$time') ";

    if ($dupeSelectStmt = $portableDB->prepare("SELECT `counter` FROM transactions WHERE (`reference` = ? AND `qdate` = ? AND `time` = ?)"))
    {
        $dupeSelectStmt->bind_param('sss',$ref, $date, $time);
        $dupeSelectStmt->bind_result($counter);
        $dupeSelectStmt->execute();

        while ($dupeSelectStmt->fetch())
        {
            break;
        }

        $numRows = $portableDB->affected_rows;

        if ($numRows > 0)
            return TRUE;
        else if ($numRows == -1)
        {
            print " ERROR: ";
            print_r($portableDB->error);
            print_r($dupeSelectStmt->error);
            return FALSE;
        }
        else
            return FALSE;
    }
}

-If I run the query by hand through Workbench on the same server, I get 24 rows returned.

–this is the same if I prepare, set, and execute the statement by hand.

-affected_rows returns -1

–same if I do num_rows on the statement

-there is no error stored on the Statement or MySQLi object.

-if I put a print in the fetch() statement, it prints one row’s worth of data

-if I store the fetched rows into an array and count the results, it’s 1

-I’ve tried running it with each variable separately, same thing.

-other queries on the same server (heck, on the same MySQLi object) are working fine. SELECTS, UPDATES, and INSERTS.

  • 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-06-11T21:19:44+00:00Added an answer on June 11, 2026 at 9:19 pm

    The answer is I was forgetting to call mysqlistmt::store_result after mysqlistmt::execute().

    Once I added $dupSelectStmt->store_result(); I was able to call $dupSelectStmt->num_rows and $portableDB->affected_rows and they both showed the 24 I knew I should be seeing.

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

Sidebar

Related Questions

Ok so this problem is baffling me. I have a custom class that all
I have this simple form that is having some CSS issues when the field
This should be a simple one: I have an observableArray object called To in
I'm running into an issue that's really baffling me. I have a container that
simple problem baffling me... i have a function: function spitHTML() { $html = '
Hello StackOverflow community, I have run into a problem that quite frankly is baffling
So, starting with Android and Java, and I have this baffling error: The application
I have encountered a somewhat baffling problem with the simple task of filling an
This is baffling me, I am unable to find this setting if it exists.
This is strange and baffling. In my ASP.NET 2.0 app I have a form

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.