stored procedure execution failed - MSSQL and php_dblib.dll
Posted: Sun Mar 02, 2008 6:37 pm
Okay, I've got a problem with mssql not running a stored procedure.
I'm on a dev box running Windows. I'm using php_dblib.dll (a windows compile of freeTDS) compiled by http://kromann.info. It's the latest release version for PHP 5.2.
Obviously, I'm using PHP 5.2.
I'm using mssql calls. The server is Microsoft SQL Server 8.0.
This is the problem code fragment:
Here's the errors I get when I try to run the stored procedure:
mssql_execute() [function.mssql-execute]: stored procedure execution failed
mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource
I'm pretty sure it's to do with having too many bound variables.
Has anyone run into a similar problem? Do I need to compile freeTDS myself or is it something simple?
Thanks in advance
I'm on a dev box running Windows. I'm using php_dblib.dll (a windows compile of freeTDS) compiled by http://kromann.info. It's the latest release version for PHP 5.2.
Obviously, I'm using PHP 5.2.
I'm using mssql calls. The server is Microsoft SQL Server 8.0.
This is the problem code fragment:
Code: Select all
//Connects to the target server
$db_c = db_connect();
//The name of the stored procedure
$q = "spOECD_Calc";
$sp = mssql_init($q, $db_c);
//Binding about 5 variables
$strStudy = "$study";
mssql_bind($sp, '@strStudy', $strStudy, SQLCHAR);
$selectList = "" . trim($val_var[0]) . " AS VAR1, " . trim($val_var[1]) . " AS VAR2, " . trim($val_var[2]) . " AS VAR3, " . trim($val_var[3]) . " AS VAR4, ";
mssql_bind($sp, '@strSelectList', $selectList, SQLVARCHAR);
$condition = "WHERE COUNTRY = " . trim($par_countries[0]);
for ($k = 1; $k < count($par_countries); $k++) {
$condition = $condition . ' OR COUNTRY = ' . trim($par_countries[$k]) ;
}
$condition = $condition . "" ;
mssql_bind($sp, '@strCondition', $condition, SQLTEXT);
$groupBy = "GROUP BY CNT, ". trim( $par_variable[0] ) ;
$orderBy = "ORDER BY CNT, ". trim( $par_variable[0] ) ;
for ($l = 1; $l < count($par_variable); $l++) {
$groupBy = $groupBy . ', ' . trim( $par_variable[$l] );
$orderBy = $orderBy . ', ' . trim( $par_variable[$l] );
}
$groupBy = $groupBy . "" ;
$orderBy = $orderBy . "" ;
mssql_bind($sp, '@strGroupBy', $groupBy, SQLVARCHAR);
mssql_bind($sp, '@strOrderBy', $orderBy, SQLVARCHAR);
//It spits out the error on the following line
$q_rslt = mssql_execute($sp);
$data[$study] = array();
$i = 0;
while ($f_row = mssql_fetch_array($q_rslt, MSSQL_ASSOC)) {
$data[$study][$i++] = $f_row;
}
mssql_execute() [function.mssql-execute]: stored procedure execution failed
mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource
I'm pretty sure it's to do with having too many bound variables.
Has anyone run into a similar problem? Do I need to compile freeTDS myself or is it something simple?
Thanks in advance