0

I dont know if I have just been staring at this too long or what..

but if I use a hardcoded query line.. it works.

if I replace those with bindParam() lines.. I get nothing?

//$calibrationDetails_sql = "SELECT equipment.*, employee.* FROM equipment, employee WHERE equipment_brand = 'Toro' AND employee_number = '1'";

$calibrationDetails_sql = "SELECT equipment.*, employee.* FROM equipment, employee WHERE equipment_brand = :equipment_number AND employee_number = :employee_number";
$calibrationDetails_stmt = $conn->prepare($calibrationDetails_sql);
$calibrationDetails_stmt->bindValue(':equipment_number', $equipment_number);
$calibrationDetails_stmt->bindValue(':employee_number', $employee_number);
$calibrationDetails_stmt->execute();
$calibrationDetails_stmt->setFetchMode(PDO::FETCH_ASSOC);   
$_calibrationDetails = $calibrationDetails_stmt->fetch(); //single row  
//$_calibrationDetails = $calibrationDetails_stmt->fetchAll(); //returns multi-dimensional array 

$colcount = $calibrationDetails_stmt->columnCount();
$rowcount = $calibrationDetails_stmt->rowCount();   
var_dump($_calibrationDetails);

if($rowcount <= 0){
    //blah blah
}else{
    //blah blah
}

if I use fetch or fetchAll.. I still get nothing returned.. IF I use the bindParam() lines.. if its hardcode.. I get my data returned correctly.

I output the variables too, to ensure I was getting $_POST data to work with in my query (its fine/correct)

What am I missing here?

whispers
  • 962
  • 1
  • 22
  • 48
  • 1
    My guess would be those values don't contain what you think they do. – miken32 Nov 16 '19 at 17:54
  • Also note you don't have to bind values. Just pass an array to `execute()` and skip binding altogether. – miken32 Nov 16 '19 at 17:55
  • Sorry for closing your question but there is very little we can do. Apparently a query with binding should work. So you can only debug the code with your own data and your own input. – Your Common Sense Nov 16 '19 at 17:55
  • @miken32 thank you I was in fact trying to use different cols/values (brand vs number) glad you could reply before the 'awesome' closing team found my post. (sigh) – whispers Nov 16 '19 at 18:01
  • I do understand your frustration but you should understand that this service is two way. It is not only to help you but you are also to help keeping it clean and usable. Thank you for understanding. – Your Common Sense Nov 16 '19 at 18:02
  • Well, I was going to vote for closure as a typo once you replied... – miken32 Nov 16 '19 at 18:06

0 Answers0