0

im a web developer but i dont know much about sql, now i can connect to the server no problem but it returns

variant Object

but in the db that info has data values. how can i convert it?

[0] => Array
    (
        [0] =>      .0000
        [1] => 70042
        [2] => POLLERA LERGA C/CUERO EN CINTO
        [3] => 1
        [4] => 28
        [5] => variant Object

        [6] => INV02
        [7] => 
        [8] =>  
        [9] => variant Object

        [10] => variant Object

        [11] => variant Object

    )

by the way I'm doing the connection with ADODB.Connection

Yair Villar
  • 195
  • 1
  • 3
  • 16

4 Answers4

1

i had to put

(string)

and it worked.

Yair Villar
  • 195
  • 1
  • 3
  • 16
0

From the manual:

The VARIANT is COM's equivalent of the PHP zval; it is a structure that can contain a value with a range of different possible types. The VARIANT class provided by the COM extension allows you to have more control over the way that PHP passes values to and from COM.

And:

PHP 5 takes a much simpler approach to handling VARIANTs; when returning a value or fetching a variant property, the variant is converted to a PHP value only when there is a direct mapping between the types that would not result in a loss of information. In all other cases, the result is returned as an instance of the VARIANT class. You can force PHP to convert or evaluate the variant as a PHP native type by using a casting operator explicitly, or implicitly casting to a string by printing it. You may use the wide range of variant functions to perform arithmetic operations on variants without forcing a conversion or risking a loss of data.

You didn't post code but this means that you can normally just print it:

echo $result;
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Álvaro González how would you suggest I go about this question I posted here http://stackoverflow.com/questions/42295574/how-to-convert-8209-array-object-variant-to-vt-variant – Joseph Feb 17 '17 at 20:45
0

Refer to this for help - i used it as a way of processing variants in php. How do you read from a multidimensional variant array returned from a COM object in PHP?

Community
  • 1
  • 1
Bill Ortell
  • 837
  • 8
  • 12
0

I've wrestled with this issue for a while and found a solution which worked for me. So let say wee need to return a records set of four values per row from the MSSQL database through ADODB. It all boils down where you cast the datatype! If you cast the datatype before copying the (variant) values into the variable of your choice (mostly some array) it will work.

Example:

$buffer = array();

$sql = "SELECT col1, col2, col3, col4 FROM tbl_mydata WHERE col1 > 100";

$rec = OpenRecordset($sql); // connect to db, make your own!

while (!$rec->EOF){

    $buffer[] = array((string)$rec->fields[0], (string)$rec->fields[1], (string)$rec->fields[2], (string)$rec->fields[3]);

    $rec->MoveNext();
}

closeRecordset($rec);

for the ADOdb docs see here the manual(http://adodb.org/dokuwiki/doku.php?id=v5:userguide:userguide_index)

Now your $buffer array is ready with string type values.

foreach($buffer as ..... blabla...
Milan
  • 3,209
  • 1
  • 35
  • 46