mysqli vs PDO Webservice Return Values
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?
