0

I have a function in my SQL Server 2008 thats return a resulset and some output variables.

From PHP, i need get the values with sqlsrv library.

I have this code, which I tested with a stored procedure and work fine.

<?php

$serverName = "(local)\MSSQLSERVER, 1433";

$connectionInfo = array(
    "Database"=>"xxxx",
    "UID"=>"xxxx", 
    "PWD"=>"xxxx"
);

$conn = sqlsrv_connect($serverName, $connectionInfo);

if(!$conn) {
    die();
}

$tsql_callSP = "{call my_function(?, ?)}";

$ret_cod = "";
$ret_desc = "";

$params = array( 
    array($ret_cod, SQLSRV_PARAM_OUT),
    array($ret_desc, SQLSRV_PARAM_OUT)
);

$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);

if( $stmt === false )
{
     debug("Error in executing statement");
     die( debug( sqlsrv_errors(), true));
}

The result of error is:

[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Error en la solicitud procedimiento 'my_function'. 'my_function' es un objeto función con valores de tabla

Is a sintaxis error i know, but i dont find examples on internet of how to do this.

I try,

$tsql_callSP = "? = {call my_function(?, ?)}";

And similar but dont works.

Any ideas?.

Thanks you.

Jibieta
  • 321
  • 2
  • 10
  • why don't you use `mssql_connect($serverName, $username, $password);` ? http://php.net/manual/en/function.mssql-connect.php – Alex Mar 17 '15 at 19:41
  • possible duplicate of [How to call stored procedure by using PHP and SQL Server 2008](http://stackoverflow.com/questions/4344609/how-to-call-stored-procedure-by-using-php-and-sql-server-2008) – Alex Mar 17 '15 at 19:44
  • is not the same, is another library and is a function not a procedure Alex. – Jibieta Mar 17 '15 at 19:46
  • I have PHP 5 and in the PHP webpage say this: Mssql: This extension is not available anymore on Windows with PHP 5.3 or later. SQLSRV, an alternative extension for MS SQL connectivity is available from Microsoft: – Jibieta Mar 17 '15 at 19:47
  • try **$tsql_callSP = "{call dbo.my_function(?, ?)}";** – Alex Mar 17 '15 at 19:57
  • Nop, dont work :(, im search and i find a guy was write the sqlsrv use odbc client, and this client dont have the feature of call a function with a return resultet. – Jibieta Mar 17 '15 at 20:06
  • http://stackoverflow.com/questions/11541894/how-to-retrieve-result-of-oracle-database-function-via-odbc – Jibieta Mar 17 '15 at 20:07
  • I don't think that is your problem. your problem is *edimiento 'my_function'. 'my_function' es* that means mssql server trying to execute your function using `my_function` alias which is wrong. what is your db object under mssql server? if you tried my `dbo.myfunctionb` call does error message change? – Alex Mar 17 '15 at 20:10

0 Answers0