0

I have the below procedure with the purpose of selecting the base column where it contains a parameter:

CREATE PROCEDURE GetMap(p_team VARCHAR(100) CHARSET 'utf8')
BEGIN
SELECT Base FROM map WHERE 
map.Base = p_team OR
Ver1 = p_team OR
Ver2 = p_team OR
Ver3 = p_team OR
Ver4 = p_team OR
Ver5 = p_team OR
Ver6 = p_team OR
Ver7 = p_team OR
Ver8 = p_team OR
Ver9 = p_team OR
Ver10 = p_team OR
Ver11 = p_team OR
Ver12 = p_team;
end //

When I try to call procedure from PHP like this :

function getMap($data){
    $query = $this->PDO->prepare("CALL GetMap(:data)");
    $query->bindParam(':data', $data);

    $ex = $query->execute();
    $res = $ex->fetchColumn();
    echo $res;
    if($res){
        return $res;
    }
    else
    {
        return $data;
    }
}

It returns an exception:

Call to a member function fetchColumn() on a non-object

How can I get Base column as a variable from the select procedure?

Toby
  • 9,696
  • 16
  • 68
  • 132
user1814358
  • 619
  • 3
  • 8
  • 17
  • Yes it's returns Base column from map table where condition is true... So when i call CALL GetMap('Haka'); it returns me base value: Haka Valkeakoski in Workbench – user1814358 Jul 08 '15 at 12:51
  • possible duplicate of [PDO Fatal error: Call to a member function fetchColumn() on a non-object](http://stackoverflow.com/questions/8948151/pdo-fatal-error-call-to-a-member-function-fetchcolumn-on-a-non-object) – Saty Jul 08 '15 at 12:55

1 Answers1

1

You are calling fetchColumn on the return value from execute and that, as you can see here, is a boolean value.

The method needs to be called on an instance of the PDOStatement class, so in your case the $query variable

That means

$res = $query->fetchColumn();

instead of

$res = $ex->fetchColumn();
mishu
  • 5,347
  • 1
  • 21
  • 39