~ overflow ~

Tag: variable

variable Object MSSQL note

by z3n on Sep.25, 2009, under Notes

Problem:

return $res->Fields['field_name']->Value;

returns `variable Object`

Solution:

return intval($res->Fields['field_name']->Value);

Explanation:

There’s no explanation, this is one of those issues that happens when you deal with microsoft. Sometimes when doing a query it returns the actual value, other times it just return into a different variable type, which needs to be converted. Good thing if you caught it before writing a more complex code and then finally dealing with crypt errors :)

Bonus:

I’ve been getting some more issues even when using this conversion, things like “Object of class variant could not be converted to string php“, this happens on null values, in order to fix i been searching around and found this, which with some changes it will be better like:

  1.   for ($col=array(),$i=0,$j=$ms_res->Fields->Count();$i < $j;$i++) {
  2.    try {
  3.     $value=$ms_res->Fields[$i]->Value;
  4.     if (trim($value) != "") {
  5.      if (gettype($value) !== 'string') {
  6.       if (settype($value,"string")) {
  7.        $col[$ms_res->Fields[$i]->Name]=$value;
  8.       }
  9.      } else {
  10.       $col[$ms_res->Fields[$i]->Name]=$value;
  11.      }
  12.     } else {
  13.      $col[$ms_res->Fields[$i]->Name]='NULL';
  14.     }
  15.    } catch (exception $e) {
  16.     _r("Exception: ".$e);
  17.    }
  18.   }

..and yes you will figure out the missing functions/vars.

Leave a Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!