T
T
Taras Labiak2015-12-16 18:54:56
PHP
Taras Labiak, 2015-12-16 18:54:56

How to call PostreSQL function in PHP using PDO?

There is a function https://gist.github.com/kissarat/cb5df1c577c5e5da2d05
I call it using $pdo->exec('SELECT descend(4)'); or $pdo->query('SELECT descend(4)')->fetch(); and i get an error

PHP Warning: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function descend(integer) line 11 at SQL statement' in php shell code:1
Stack trace:
#0 php shell code(1): PDO->query('SELECT descend(...')

The trick is that before I made changes to this function (instead of _type.degree it was 4) the call worked and returned values. Here is the original code making the call
$parent_id = SQL::queryCell('SELECT descend(:root_id)', [
            ':root_id' => $this->id
        ]);

where SQL class https://gist.github.com/kissarat/9117b654fc66877441d7

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill, 2015-12-16
@kissarat

SELECT root_id, level, count(*) as count FROM matrix GROUP BY root_id, level
    HAVING count(*) < power(_type.degree, level);

It returns nothing and nowhere, which is what postgres says, and asks to call it as PERFORM if you really need it, apparently you need INTO in _count, _level, etc ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question