Highlighted

mysqli vs PDO Webservice Return Values

Engaged ,
Apr 06, 2017

Copy link to clipboard

Copied

I have a dynamic werbservice that I was unable to find a way to bind the variables to in mysqli, the default for Flex webservices, but was able to find a nice solution using PDO. The problem I have run into is that PDO does not seem to have a bind_result function like mysqli. So the problem is that I am unable to find a clean way to return my results in a way that I can set my return values for the webservice in Flex. It is just returning an object. So in PDO, I am doing this:

    $result = $stmt->fetchAll(PDO::FETCH_OBJ);  // I have tried FETCH_ASSOC also

    return $result;

In mysqli, this is what is typically done:

    while (mysqli_stmt_fetch($stmt)) {
      $rows
[] = $row;
      $row
= new stdClass();
      mysqli_stmt_bind_result
($stmt, $row->uniqueID, $row->latitude, $row->longitude);
    }

When I do a var_dump of the PDO $result, I get the following:

array(25) {
 
[0]=>
  
object(stdClass)#3 (3) {
  
["uniqueID"]=>
  
int(12335513)
  
["latitude"]=>
  
float(39.6586675)
  
["longitude"]=>
  
float(-86.0648281)
 
}
 
[1]=>
 
object(stdClass)#4 (3) {
  
["uniqueID"]=>
  
int(12368285)
  
["latitude"]=>
  
float(39.6176244)
  
["longitude"]=>
  
float(-86.8947852)
 
}

When I do a var_dump of mysqli $rows, I get the following:

array(25) {
 
[0]=>
 
object(stdClass)#3 (3) {
  
["uniqueID"]=>
  
int(12335513)
  
["latitude"]=>
  
float(39.6586675)
  
["longitude"]=>
  
float(-86.0648281)
 
}
 
[1]=>
 
object(stdClass)#4 (3) {
  
["uniqueID"]=>
  
int(12368285)
  
["latitude"]=>
  
float(39.6176244)
  
["longitude"]=>
  
float(-86.8947852)
 
}

They look exactly the same to me, but when I set up my services with mysqli, I am able to set the return type for all the variables in the array, and in PDO, Flex only sees an object returned. I want it to come back as an arraycollection. Is there a way I should return the data in PDO so that I am able to send back an array with datatypes instead of an object? Any ideas?

TOPICS
Development

Views

234

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

mysqli vs PDO Webservice Return Values

Engaged ,
Apr 06, 2017

Copy link to clipboard

Copied

I have a dynamic werbservice that I was unable to find a way to bind the variables to in mysqli, the default for Flex webservices, but was able to find a nice solution using PDO. The problem I have run into is that PDO does not seem to have a bind_result function like mysqli. So the problem is that I am unable to find a clean way to return my results in a way that I can set my return values for the webservice in Flex. It is just returning an object. So in PDO, I am doing this:

    $result = $stmt->fetchAll(PDO::FETCH_OBJ);  // I have tried FETCH_ASSOC also

    return $result;

In mysqli, this is what is typically done:

    while (mysqli_stmt_fetch($stmt)) {
      $rows
[] = $row;
      $row
= new stdClass();
      mysqli_stmt_bind_result
($stmt, $row->uniqueID, $row->latitude, $row->longitude);
    }

When I do a var_dump of the PDO $result, I get the following:

array(25) {
 
[0]=>
  
object(stdClass)#3 (3) {
  
["uniqueID"]=>
  
int(12335513)
  
["latitude"]=>
  
float(39.6586675)
  
["longitude"]=>
  
float(-86.0648281)
 
}
 
[1]=>
 
object(stdClass)#4 (3) {
  
["uniqueID"]=>
  
int(12368285)
  
["latitude"]=>
  
float(39.6176244)
  
["longitude"]=>
  
float(-86.8947852)
 
}

When I do a var_dump of mysqli $rows, I get the following:

array(25) {
 
[0]=>
 
object(stdClass)#3 (3) {
  
["uniqueID"]=>
  
int(12335513)
  
["latitude"]=>
  
float(39.6586675)
  
["longitude"]=>
  
float(-86.0648281)
 
}
 
[1]=>
 
object(stdClass)#4 (3) {
  
["uniqueID"]=>
  
int(12368285)
  
["latitude"]=>
  
float(39.6176244)
  
["longitude"]=>
  
float(-86.8947852)
 
}

They look exactly the same to me, but when I set up my services with mysqli, I am able to set the return type for all the variables in the array, and in PDO, Flex only sees an object returned. I want it to come back as an arraycollection. Is there a way I should return the data in PDO so that I am able to send back an array with datatypes instead of an object? Any ideas?

TOPICS
Development

Views

235

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 06, 2017 0
Engaged ,
Apr 06, 2017

Copy link to clipboard

Copied

So I tried constructing an array of objects the way that it seems that mysqli does from the result set, and it still does not work.  Flex is still seeing it returned as a primitive object.  I am at a total loss guys.  Here is what I did in php:

            $result = $stmt->fetchAll(PDO::FETCH_OBJ);

           

            $rows = array();

           

            foreach ($result as $res) {

                $row = new stdClass();

                $row->uniqueID=$res->uniqueID;

                $row->latitude=$res->latitude;

                $row->longitude=$res->longitude;

                $rows[]=$row;

            }

       

            return $rows;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 06, 2017 0