-1

I have been checking for more than an hour but i cant get the result, my question is, by checking two columns it must display the other columns value as result using PDO.

$sql ="SELECT column3 FROM tablename WHERE column1 = :request AND column2= :recived";
$conn = $conn->prepare($sql);
$fetch = $conn->execute(array(':request'=> $value1,':recived'=>$value2));
$fetch = $fetch->fetchColumn();

please help me with this. Thanks in advance

3 Answers3

1

This is what you looking for :

<?php

$sql ="SELECT column3 FROM tablename WHERE column1 = :request AND column2= :recived";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':request'=> $value1,':recived'=>$value2));
$fetch = $stmt->fetchColumn();
?>
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
0

Change it as such:

$sql ="SELECT column3 FROM tablename WHERE column1 = :request AND column2= :recived";
$conn = $conn->prepare($sql);
$conn->execute(array(':request'=> $value1,':recived'=>$value2));
$fetch = $conn ->fetchColumn();

You should call fetchColumn() on the statement. Because execute() only returns a boolean as result.

Johan
  • 931
  • 9
  • 23
0

execute() returns a boolean and you're trying to call fetchColumn() on it. Call fetchColumn() on the statement instead:

$fetch = $conn->fetchColumn();

For future debugging, check your error log because there will be a message indicating the problem here.

MrCode
  • 63,975
  • 10
  • 90
  • 112