0

Ugh. I've spent hours searching for a solution for this, so it's probably something simple. I have a stored procedure in SQL Server (2008) that I'm trying to call from PHP code. I'm using ODBC, and everything works if I use a hard-coded SQL statement.

But I'm trying to call a stored procedure that returns a set of rows (cursor, dataset, etc.), passing two parameters. When I run the code through my browser I just get a 500 http error. It is bombing on the odbc_execute() line. Here's my code:

// DSN-less connection:
$conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", '', '');
if (!$conn)
   {exit("Connection Failed: " . $conn);}
$fromDate = new DateTime('2012-1-1');
$toDate = new DateTime('2013-12-31');

$sql = odbc_prepare($conn, "{call GET_EVENTS_BY_DATE_RANGE(?, ?)}");
$params = array($fromDate, $toDate);

$result = odbc_execute($sql, $params);  
if ( $result === false)
{
exit("Query failed");
}

odbc_close($conn);

Again, no problems until it hits the odbc_execute() function. Any help is appreciated.

4
  • If you want help with this, you need to provide more information than "500 error" - this is a generic, friendly error - you need to turn off friendly errors and find out what the actual error is... Commented Feb 8, 2014 at 2:03
  • Crap, you're right. Sorry. Here's the error: PHP Warning: odbc_execute(): SQL error: [Microsoft][ODBC SQL Server Driver]Cursor type changed, SQL state 01S02 in SQLExecute in C:\bleah\sp.php on line 24 Commented Feb 8, 2014 at 2:06
  • Maybe this helps? stackoverflow.com/questions/8011526/… Commented Feb 8, 2014 at 13:10
  • @JensMühlenhoff That was a good link, thanks, but the solution(s) that worked for that person (using odbc_exec instead of odbc_execute) returned a different error for me (warning, actually): odbc_exec() expects parameter 2 to be string, array given in C:\.... Commented Feb 8, 2014 at 18:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.