T
T
Tatiana2019-12-14 16:36:32
PHP
Tatiana, 2019-12-14 16:36:32

How to get value of input/output parameter via pdo dblib?

MSSQL base.
php code:

$pdo = new \PDO("dblib:host=  ;dbname= ;charset=utf8", $login, $password );
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$id = 0;
$name = 'текст';
$stm = $pdo->prepare(" EXEC   [dbo].[SAVE]    :id, :name  "); 
$stm->bindParam(":id", $id,\PDO::PARAM_INT|\PDO::PARAM_INPUT_OUTPUT , 4);
$stm->bindParam(":name", $name, \PDO::PARAM_STR, 255);
var_dump($stm->execute()); //true
var_dump($stm2->fetchAll(\PDO::FETCH_OBJ));

How can I return $id ( it is an input/output parameter) ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2019-12-15
@FurmanTania

In a stored procedure, first specify SET NOCOUNT ON.
If it doesn't work, return your parameters viaSELECT

Unfortunately, there is no right to change the procedure
Then pass to someone with rights: INPUT_OUTPUT does not work .
Or create your own:
CREATE PROCEDURE SaveTania @ID INT, @NAME VARCHAR(255) 
AS BEGIN
  SET NOCOUNT ON
  EXECUTE [dbo].[SAVE] @ID, @NAME
  SELECT @ID, @NAME
END

L
Lev Zabudkin, 2019-12-14
@zabudkin

Well, its input is 0.
And so you get to the elementary one - PDO::lastInsertId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question