0

I have been fighting for my life with prepared statements. Every site I've tried has different syntax. Here's what I'm trying to accomplish:

$stmt = $mysqli->prepare("SELECT IdNum FROM TOAWorkOrdersNew WHERE WorkDate = ? AND TechNum = ?");
$stmt2 = $mysqli->prepare("SELECT IdNum FROM CallVolume WHERE WorkDate = ? AND ANI = ?");

---loop
    ----loop

    $stmt->bind_param('ss', $IncDate, $TechNum);
$stmt->execute();
$stmt->store_result();

$WorkOrders = $stmt->num_rows;
$SubWorkOrders = $SubWorkOrders + $WorkOrders;

$stmt->free_result();
$stmt->close();


$stmt2->bind_param('ss', $IncDate, $CellNum);
$stmt2->execute();
$stmt2->store_result();


$CallCount = $stmt2->num_rows;
$SubCallCount = $SubCallCount + $CallCount;

$stmt2->free_result();
$stmt2->close();

    }
}

The statements are returning NULL.

1
  • Which statements are returning NULL? Commented Jul 8, 2013 at 19:05

1 Answer 1

1

You shouldn't call $stmt->close() inside the loop. Once you close the statement, it no longer remembers what it was prepared with.

Also, you don't need to call $stmt->bind_param() each time through the loop. Parameters are bound to references, so you can do this once before the loop, and then just update the variables inside the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.