When I consult an SP with PHP-SQL Server-PDO and use output variables plus set of results. The variables return empty

0

I'm having two problems so to speak with PHP - SQL Server . I am trying to work stored procedures with PHP using database SQL Server .

I put the code PHP with PDO :

$opciones = array(
    PDO::ATTR_PERSISTENT => true,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);

//Conexión con SQL Server:
dbh= new PDO($dsn, $this->usuario, $this->password,$opciones);

$ip = '10.10.10.11';

//Preparando Consulta
$sql = "exec SpClave :ip,:clave";
$stmt = dbh->prepare($sql); 

//Cargando Parametros 
stmt->bindParam(":ip", $ip,PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT);
stmt->bindParam(":clave", $clave);

//Ejecutar Consulta
$result = tmt->execute();  

//Cargar Conjuntos de Datos
stmt->fetchAll(PDO::FETCH_ASSOC);

Well, it connects to the DB and runs from SP . But for some reason I do not associate the output variable so to speak. It is always empty. It also shows no error of any kind.

Now, I made this change:

$sql = "exec SpClave '10.10.10.11',:clave";

with:

stmt->bindParam(":clave", $clave);

And now if I associate the output variable.

  • This is the first problem, which in theory is solved but I do not know why this happens, if only I associate the output variables.
  • Yes I try to retrieve a set of results (Understand a Select), more output variables and input variables. I can only retrieve the result set and it also shows no error.
  • Les coloco el sp:

    CREATE PROCEDURE [dbo].[SpClave] 
        @ip varchar(255),
        @clave varchar(255) output                          
    AS
    SET NOCOUNT ON;
    select 'Prueba1';
    set @clave='Prueba2';
    

    Well I made many changes and read the documentation but I can not reverse this, I do not know if I'm missing something, but I stay here.

    The sp were used in asp.net and without problems I could work. Now it is necessary to integrate PHP with these SP in sql server and I am having these problems. The controller you use is php_pdo_odbc , just change and use this library php_sqlsrv_7 to see if it was due to problems of driver , change the code and the same thing happens.

    I hope you can help me or guide me in any case and thank you very much for your time, regards.

        
    asked by Luis Sánchez 30.08.2018 в 23:02
    source

    0 answers