A
A
Alf1622013-07-07 16:41:37
PHP
Alf162, 2013-07-07 16:41:37

Calling a stored procedure php PDO, firebird?

Hello. It is impossible to execute HP by means of PDO. The procedure itself:

CREATE PROCEDURE P_NAME_ID(<br>
    INTAB VARCHAR(10),<br>
    NAME VARCHAR(60))<br>
RETURNS (<br>
    ID INTEGER,<br>
    PNO SMALLINT)<br>
AS<br>
DECLARE VARIABLE UPNAME VARCHAR(60);<br>
begin<br>
 if (INTAB = 'TGOS')  then begin<br>
  if ( NOT EXISTS(select ID from TGOS where UPPER(GOS) = :UPNAME) ) then begin<br>
    insert into TGOS (GOS) values (:NAME);   /* пишем, что пришло */<br>
    PNO = 1;<br>
  end<br>
  select ID from TGOS where UPPER(GOS) = :UPNAME into :ID;<br>
  Exit;<br>
 end<br>
.....<br>

I'm calling it properly:
$sql="CALL P_NAME_ID (?,?,?,?)";<br>
$sth = $dbo->prepare($sql);<br>
$sth->bindParam(1, 'TFAM', PDO::PARAM_STR);<br>
$sth->bindParam(2, 'Post body', PDO::PARAM_STR);<br>
$sth->bindParam(3, $id, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 11);<br>
$sth->bindParam(4, $id_, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 11);<br>
$sth->execute();<br>

In response, I get Fatal error: Call to a member function bindParam() on a non-object
What is my mistake?

Answer the question

In order to leave comments, you need to log in

9 answer(s)
A
Alf162, 2013-07-08
@Alf162

Apparently the problem is still with PDO. It will be correct like this:

$sql="EXECUTE PROCEDURE P_NAME_ID ('TFAM','Post body')";
$sth = $dbo->prepare($sql);
$r = $res->fetchAll();

Then $r will return the result of the procedure execution. But it doesn't work for some reason. But it works without PDO:
$db = ibase_connect($database, $user, $password)or die($err_logon);
$sql= "EXECUTE PROCEDURE P_NAME_ID ('TFAM','Post body')";
$sql_res = ibase_query($sql, $db);

M
Maxim Dyachenko, 2013-07-07
@Mendel

Everything points to the error here:

$sql="CALL P_NAME_ID (?,?,?,?)";

I don't know firebird, so I can't tell you any further. But the lack of a semicolon cuts the eye. In theory, it is not mandatory, but ...
PS: Google didn’t give me anything about
it, but it gave me about
CALL P_NAME_ID

EXECUTE PROCEDURE

Are you sure about the syntax?
Direct execution of the instruction in the console does not produce an error?

D
Domini, 2013-07-07
@Domini

Link

$sql="EXECUTE P_NAME_ID (:INTAB,:NAME,:ID,:PNO)";
$sth = $dbo->prepare($sql);
$sth->bindParam(':INTAB', 'TFAM', PDO::PARAM_STR);
$sth->bindParam(':NAME', 'Post body', PDO::PARAM_STR);
$sth->bindParam(':ID', $id, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 11);
$sth->bindParam(':PNO', $id_, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 11);

A
Andrew, 2013-07-07
@Morfi

prepare() did not return PDOStatement, most likely it returned false, why it did so, you need to look at the documentation.

A
Alf162, 2013-07-07
@Alf162

Everything is fine without procedures.

A
Anton Medvedev, 2013-07-07
@Elfet

$sth->bindParam(1, 'TFAM', PDO::PARAM_STR);

Change to:
$sth->bindValue(1, 'TFAM', PDO::PARAM_STR);

A
Anton Medvedev, 2013-07-07
@Elfet

> Fatal error: Call to a member function bindParam() on a non-object
Error in this. Translate the error. :)

S
svd71, 2013-07-10
@svd71

In order for the procedure to return parameters, you need to add the following line to it:

...
  select ID from TGOS where UPPER(GOS) = :UPNAME into :ID;
SUSPEND;
  Exit;
....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question