greenMind homepage about / projects / clients / services / contact    
 
 

< Fixing PHP/MS SQl problems >

< SQL_CUR_USE_ODBC : A quick trick to troubleshoot SQL Server woes>

< Using the odbc_ functions in php tend to be flexible, since they rely on a solid ODBC connection, rather than the proper installation of a specific database driver.

There are certain irksome problems that come up with SQL Server in particular, especially when working with stored procedures.

Recently, I attempted to step through a paged subset of a recordset using a for loop.

for($i=$base;$i<$top;$i++){##fetch fields 
  $id = odbc_result($rs, "id");
  $f1 = odbc_result($rs, "f1");
  $f2 = odbc_result($rs, "f2");
  $f3= odbc_result($rs, "f3");
This worked great with raw dynamic sql executed, but utterly failed when using a stored procedure (which I recommend for security and modularity).

The solution: a constant briefly mentioned in the documention in PHP.net for the function odbc_connect:

resource odbc_connect ( string dsn, string user, string password [, int cursor_type] )
You can substitute the cursor_type integer with a constant, and it'll look like this:
$conn = odbc_connect("sqlDSN","naughy exposed user","naughty plain text password",SQL_CUR_USE_ODBC)

And now you can iterate through your sproc results, and return things like the @@identity.
>