You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by bilbosax <wa...@comcast.net> on 2017/04/06 04:47:48 UTC

PDO vs mysqli Web Service Return Values

I have a dynamic werbservice that I was unable to find a way to bind the
variables in mysqli, the default for Flex webservices, but was able to find
a nice solution to 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 set my return values from the webservice
in Flex.  It is just returning an object.  So in PDO, I am doing this:

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

I assumed this would return an array, as that is how it traces out in PHP,
but it is instead returning what Flex sees as an object.  In mysqli, we do
this:

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

As a result, MLSNum, latitude, and longitude can all be given a datatype in
Flex individually.  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?

Thanks for any insight!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
After almost 10 days of fighting with PHP and Flex, I found my solution.  It
is one of the most embarrassing, humiliating, and time-wasting things I have
ever run into in programming, but I feel like I should post the solution
just in case anybody ever reads this (smh). The solution had nothing to do
with a problem with PDO, mysqli, or PHP at all, and it had nothing to do
with Flex at all either.  The solution was simply:

Quotes ' '

When you try and set return values from the database into valueObjects, you
have to give Flex a set of input variables in order for it to obtain some
data from the database to analyze.  I put in integers for ints, numbers for
nums, and for strings, I put in characters between single quotes like
'Indianapolis'.  That was my mistake.  Flash Builder just wants you to put
in characters, no quotes.  If you include quotes, you don't get an error,
but I guess the database gives you back no data, and Flex interprets the
results as a primitive object since there is no appreciable data stream to
analyze.  If you take out the quotes, Flex sees all the fields and sets up
valueObjects with the appropriate data types.

What a colossal waste of time!!! On the bright side, I sure can program a
service in PHP in both mysqli and PDO now LOL



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p15004.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
I hear what you are saying, but I don't think I understand what I need to do.
The services are written in PHP and they communicate with Flex using Zend
AMF. There isn't any tags or code in the PHP files that indicate to use AMF,
I think that it just automatically happens with Zend.

Which brings us to the Flex side. When I connect to a PHP service file, why
would Flex recognize the type identifiers in the data stream in one PHP
service, but not the other? I have never had to mess with registerClassAlias
to get Flex to recognize the type identifiers before, so I feel like
something must be wrong on the PHP side, on what or how I am sending it.

I'm probably missing something in my thinking. Could you perhaps give me a
little more direction on steps I could take to help identify the problem, or
what I need to do on the Flex side to get it to recognize the type
identifiers in the data stream?

Thanks



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p15002.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by Alex Harui <ah...@adobe.com>.
Bits are just bits.  Some look like readable characters, others do not.
When you send bits from a server to a Flex app, there has to be an
agreement as to what the bits mean.  If you want to send bits that become
useful instances of data classes or value objects in Flex, you have to use
AMF or SOAP and have the right decoder/encoder set up on the Flex side.
Otherwise, you are going to get plain objects or ObjectProxy instances.

I've never used PDO or MySQL.  I'm unclear what you are using to encode
the type information in the bits.  I seem to recall that PHP has an AMF
capability.  Not sure what MySQL APIs you are using.

If you are using AMF, you have to have the registerClassAlias calls match
the type identifier in the data stream.

HTH,
-Alex

On 4/7/17, 9:06 PM, "bilbosax" <wa...@comcast.net> wrote:

>OK, now I am truly baffled, more so than usual :) Before attempting to
>look
>at network traffic, I decided to do a little test, totally forgetting
>about
>PDO.  I did this all in mysqli, which is what flex generates if you ask it
>to build a service.  I had flex generate a service for a table with three
>columns.  When I set the return types, it generated a string and two
>numbers
>- working perfectly.  I then created my own service using the same order
>and
>structure of mysqli code as the service Flex generated.  There were two
>notable differences.  One is that my service is dynamic and has to bind
>the
>variables using an array instead of individual parameters.  I don't think
>this should make a difference.  The second is that my service has 59
>columns
>to retrieve instead of 3.  When I try to set the return types on MY
>service,
>I get a primitive object instead of individually typed fields.
>
>So, it doesn't seem to matter in my case whether I use PDO or mysqli, my
>return type is always a primitive object.  Why is this???
>
>My only guess is that Flex is unable or unwilling to type that many
>columns,
>and therefore just defaults to a primitive object, and leaves it up to me
>to
>handle inside of Flex instead of in PHP.
>
>Any thoughts???
>
>
>
>--
>View this message in context:
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle
>x-users.2333346.n4.nabble.com%2FPDO-vs-mysqli-Web-Service-Return-Values-tp
>14970p14999.html&data=02%7C01%7C%7Cdc1194482d654719592b08d47e35eb9d%7Cfa7b
>1b5a7b34438794aed2c178decee1%7C0%7C0%7C636272217453822794&sdata=UNsG2%2F2J
>hSrNYbuGadosBMwv1u%2BKnTfmOSQYH5R%2BGjY%3D&reserved=0
>Sent from the Apache Flex Users mailing list archive at Nabble.com.


Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
OK, now I am truly baffled, more so than usual :) Before attempting to look
at network traffic, I decided to do a little test, totally forgetting about
PDO.  I did this all in mysqli, which is what flex generates if you ask it
to build a service.  I had flex generate a service for a table with three
columns.  When I set the return types, it generated a string and two numbers
- working perfectly.  I then created my own service using the same order and
structure of mysqli code as the service Flex generated.  There were two
notable differences.  One is that my service is dynamic and has to bind the
variables using an array instead of individual parameters.  I don't think
this should make a difference.  The second is that my service has 59 columns
to retrieve instead of 3.  When I try to set the return types on MY service,
I get a primitive object instead of individually typed fields.

So, it doesn't seem to matter in my case whether I use PDO or mysqli, my
return type is always a primitive object.  Why is this???

My only guess is that Flex is unable or unwilling to type that many columns,
and therefore just defaults to a primitive object, and leaves it up to me to
handle inside of Flex instead of in PHP.

Any thoughts???



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p14999.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
I'll look into it and post back. Even if I were to do it, I am not sure that
I would understand what I am looking at as I am pretty sure it will not look
like an array flowing through the network to my eyes. But I have never done
it so we will see.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p14994.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by Tom Chiverton <tc...@extravision.com>.
Can you put WireShark or something on the network and see what the 
decoded network traffic looks like ?

Tom


On 07/04/17 08:02, bilbosax wrote:
>   I'm at a loss because
> a var_dump of the mysqli and PDO results show the EXACT same result
> structure. If they are the same, why does flex not see them as the same? Why


Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
I'm sure that I could do that. I could pull the object into AIR and typecast
and break it into an arraycollection, but that just feels sloppy and
inefficient and slow. The web service structure was set up to help you
typecast your incoming data so you get exactly what you want from your
database. I want individualized fields, not an object. I'm at a loss because
a var_dump of the mysqli and PDO results show the EXACT same result
structure. If they are the same, why does flex not see them as the same? Why
will it pull one format into the app flawlessly, and the other as a
primitive object? It just doesn't make sense, I must be missing something
simple.

Surely someone has written a service in PDO haven't they? Where are you at
guys?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p14983.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by Deepak MS <me...@gmail.com>.
Since you are anyway looping to typecast the values in php, can you just
fetch objects using PDO(without loop), loop them in flex and type cast
instead? If that will be of help.

Or try using httpservice instead of webservice to call the php. That may
typecast it for you. I'm not sure on it, but worth a try.

On 7 Apr 2017 8:48 am, "bilbosax" <wa...@comcast.net> wrote:

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;



--
View this message in context: http://apache-flex-users.
2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-
Values-tp14970p14981.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
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;



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p14981.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by bilbosax <wa...@comcast.net>.
I am using PHP version 5.6.19.  So I took a long look at the documentation
and the msqli examples that Flex generates and noticed that it would
initialize the $row variable to a stdclass.  So, in PDO, I changed the
PDO::Fetch_Assoc parameter to PDO::Fetch_Obj.  When I do a var_dump, this is
what mysqli traces out:

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 in PDO, this is what it looks like:

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.  Any ideas?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/PDO-vs-mysqli-Web-Service-Return-Values-tp14970p14980.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: PDO vs mysqli Web Service Return Values

Posted by Tom Chiverton <tc...@extravision.com>.
This is PHP version ... ?

My thought is that fetchAll() is returning a recordset/cursor, not an 
array, and there is magic going on when it's "trace"'d out.

So you'll need to convert it to a real array of objects. I dunno if PDO 
has a method for that or if you'll need to build it yourself with a loop.

Tom


On 06/04/17 05:47, bilbosax wrote:
> I am unable to find a clean way to set my return values from the webservice
> in Flex.  It is just returning an object.  So in PDO, I am doing this:
>
> $result = $stmt->fetchAll(PDO::FETCH_ASSOC);		
> return $result;