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/10/05 02:23:59 UTC

RemoteObject, PHP, and Zend

I am new to PHP, so I apologize for my inexperience. I am working in a
Windows 10 environment and have installed WAMP to serve Apache, PHP, and
MySQL. I am creating some remoteObject webservices for an Adobe AIR app that
will communicate with Zend using AMF, and I have created an index.php file
to get everything in motion, but when I browse to the index.php file in
chrome, I get all kinds of errors. Here is the index.php file:

*index.php*
<?php
       require_once('Zend/Amf/Server.php');
       require_once('HalfService.php');
    
       $server = new Zend_Amf_Server();
       //adding our class to Zend AMF Server
       $server->setClass("HalfService");
       //Mapping the ActionScript VO to the PHP VO
       //you don't have to add the package name
       $server->setClassMap("VOService", "VOService");
       echo($server -> handle());
?>

*My file structure in WAMP is as follows:*

C:/wamp64/www/
                          ZendFramework/library/Zend/Amf/Server.php
                          zendamf_remote/index.php
                                                   HalfService.php
                                                   VOService.php

*I tried to create a include_path in my php.ini file that looks like this,
but it did not work:*

    include_path = “c:\wamp64\www\ZendFramework\library”

*Finally, this is the error that I get when I browse to index.php in a
browser:*

    ( ! ) Warning: require_once(Zend/Amf/Server.php): failed to open stream:
No such file or directory in C:\wamp64\www\zendamf_remote\index.php on line
2
    
    ( ! ) Fatal error: require_once(): Failed opening required
'Zend/Amf/Server.php' (include_path='�c:\wamp64\www\ZendFramework\library�')
in C:\wamp64\www\zendamf_remote\index.php on line 2

I thought that surely someone here might have tried to create their own
RemoteObjects to try and communicate with a database in AMF.  Any help at
all in getting this configured would really be appreciated.  Thanks so much!





--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: RemoteObject, PHP, and Zend

Posted by Vincent Sotto <ds...@gmail.com>.
well if you use flashbuilder, fb will generate the services for you, but
your limited fo zend 1.x

On Thu, Oct 5, 2017 at 10:23 AM, bilbosax <wa...@comcast.net> wrote:

> I am new to PHP, so I apologize for my inexperience. I am working in a
> Windows 10 environment and have installed WAMP to serve Apache, PHP, and
> MySQL. I am creating some remoteObject webservices for an Adobe AIR app
> that
> will communicate with Zend using AMF, and I have created an index.php file
> to get everything in motion, but when I browse to the index.php file in
> chrome, I get all kinds of errors. Here is the index.php file:
>
> *index.php*
> <?php
>        require_once('Zend/Amf/Server.php');
>        require_once('HalfService.php');
>
>        $server = new Zend_Amf_Server();
>        //adding our class to Zend AMF Server
>        $server->setClass("HalfService");
>        //Mapping the ActionScript VO to the PHP VO
>        //you don't have to add the package name
>        $server->setClassMap("VOService", "VOService");
>        echo($server -> handle());
> ?>
>
> *My file structure in WAMP is as follows:*
>
> C:/wamp64/www/
>                           ZendFramework/library/Zend/Amf/Server.php
>                           zendamf_remote/index.php
>                                                    HalfService.php
>                                                    VOService.php
>
> *I tried to create a include_path in my php.ini file that looks like this,
> but it did not work:*
>
>     include_path = “c:\wamp64\www\ZendFramework\library”
>
> *Finally, this is the error that I get when I browse to index.php in a
> browser:*
>
>     ( ! ) Warning: require_once(Zend/Amf/Server.php): failed to open
> stream:
> No such file or directory in C:\wamp64\www\zendamf_remote\index.php on
> line
> 2
>
>     ( ! ) Fatal error: require_once(): Failed opening required
> 'Zend/Amf/Server.php' (include_path='�c:\wamp64\www\
> ZendFramework\library�')
> in C:\wamp64\www\zendamf_remote\index.php on line 2
>
> I thought that surely someone here might have tried to create their own
> RemoteObjects to try and communicate with a database in AMF.  Any help at
> all in getting this configured would really be appreciated.  Thanks so
> much!
>
>
>
>
>
> --
> Sent from: http://apache-flex-users.2333346.n4.nabble.com/
>

Re: RemoteObject, PHP, and Zend

Posted by bilbosax <wa...@comcast.net>.
Got a real challenge for you.  I am trying to use RemoteObject and AMF to get
some data out of my database.  Two of the functions in my PHP class work
great, count and gethalf.  But the gethalfcomps function always gets me the
following error:

[RPC Fault faultString="Channel disconnected"
faultCode="Client.Error.DeliveryInDoubt" faultDetail="Channel disconnected
before an acknowledgement was received"]

How two of the functions operate correctly and one does not is baffling to
me.  Any even random thoughts on possibilities would be greatly appreciated. 
The function that I am struggling with is getHalfComps. Here is the PHP
code:

<?php

/**
 *  README for sample service
 *
 *  This generated sample service contains functions that illustrate typical
service operations.
 *  Use these functions as a starting point for creating your own service
implementation. Modify the 
 *  function signatures, references to the database, and implementation
according to your needs. 
 *  Delete the functions that you do not use.
 *
 *  Save your changes and return to Flash Builder. In Flash Builder
Data/Services View, refresh 
 *  the service. Then drag service operations onto user interface components
in Design View. For 
 *  example, drag the getAllItems() operation onto a DataGrid.
 *  
 *  This code is for prototyping only.
 *  
 *  Authenticate the user prior to allowing them to call these methods. You
can find more 
 *  information at http://www.adobe.com/go/flex_security
 *
 */

define("DATABASE_SERVER", "localhost");
define("DATABASE_PORT", "3306");
define("DATABASE_USERNAME", {myusername});
define("DATABASE_PASSWORD", {mypassword});
define("DATABASE_NAME", {mydatabasename});

class HalfService {

	/**
	 * The constructor initializes the connection to database. Everytime a
request is 
	 * received by Zend AMF, an instance of the service class is created and
then the
	 * requested method is invoked.
	 */
	public function __construct() {
                try{
                    $this->pdo = new
PDO('mysql:host='.DATABASE_SERVER.';port='.DATABASE_PORT.';dbname='.DATABASE_NAME,
DATABASE_USERNAME, DATABASE_PASSWORD);
                    $this->pdo->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
                    $this->pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES,
false );
                }
                catch(PDOException $e){
                    $error =  "Connection failed: " . $e->getMessage();
                }
	}

	/**
	 * Returns rows from the table.
	 *
	 * Add authroization or any logical checks for secure access to your data 
	 *
	 * @return array
	 */
	public function getHalf($itemst, $itemci, $itempc, $itempbmin, $itempbmax,
$itemapmin, $itemapmax, $itemprmin, $itemprmax, $itemprofit, $itemdom,
$itembu, $itemsd, $itemsu, $itempt, $itembeds, $itembaths, $itemsqft,
$itemdi) {

            $itemst2 = [$itemst];
            $itempc2 = [$itempc];
            $itempbmin2 = [$itempbmin];
            $itempbmax2 = [$itempbmax];
            $itemapmin2 = [$itemapmin];
            $itemapmax2 = [$itemapmax];
            $itemprmin2 = [$itemprmin];
            $itemprmax2 = [$itemprmax];
            $itemprofit2 = [$itemprofit];
            $itemdom2 = [$itemdom];
            $itembu2 = [$itembu];
            $itembeds2 = [$itembeds];
            $itembaths2 = [$itembaths];
            $itemsqft2 = [$itemsqft];
            $itemdi2 = [$itemdi];
            $container = explode(',', $itempt);
            $bindStr = implode(",", array_map(function($val) { return "?";
}, $container)); 
            $queryString = "SELECT uniqueID, address, appliances,
architecturalStyle, area, areasInterior, auctionCompanyName, auctionDate,
auctionTime, averagePrice, basement, basementDescription, bathsFull,
bathsHalf, bathsTotal, beds, built, "
                                    ."city, cool, countyOrParish,
dateClosed, dateListed, disclosures, dom, equipment, exterior,
exteriorAmenities, fireplace, fireplaceDescription, foundation, fuel,
garage, hasComps, "
                                    ."heat, interior, latitude, levels,
longitude, lotInformation, lotSize, listAgentFullName, listOfficeName,
mandatoryFee, mandatoryFeeIncludes, mandatoryFeePaid,
masterBedroomDescription, "
                                    ."modifiedDT, MLSName, MLSNum, perBelow,
porch, price, profit, propCount, propDescription, propType, schoolDistrict,
semiAnnualPropertyTaxAmt, sqFtMain, sqFtTotal, "
                                    ."state, status, subdivision, taxYear,
totalNumOfAcres, township, url, utilityOptions, utilityPrimSewageDisp,
utilityPrimWaterSource, zipcode FROM half WHERE (state=?) AND (propCount >=
?) AND "
                                    ."(perBelow >= ?) AND (perBelow <= ?)
AND (averagePrice >= ?) AND (averagePrice <= ?) AND (price >= ?) AND (price
<= ?) AND "
                                    ."(profit >= ?) AND
((UNIX_TIMESTAMP(NOW())*1000 - dateListed)/86400000 <= ?) AND (built <= ?)
AND (beds >= ?) AND (bathsTotal >= ?) AND (sqFtTotal >= ?) AND (propType IN
({$bindStr})) AND (? IS NULL OR disclosures = ?)";

            $params = array();
            $params = array_values(array_merge($itemst2,$itempc2,
$itempbmin2, $itempbmax2, $itemapmin2, $itemapmax2, $itemprmin2,
$itemprmax2, $itemprofit2, $itemdom2, $itembu2, $itembeds2, $itembaths2,
$itemsqft2, $container, $itemdi2, $itemdi2));
                                                           
            if ($itemsd == NULL && $itemsu == NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $queryString = $queryString." AND (address LIKE ? OR
MLSNum LIKE ? OR city LIKE ?)";
                    $params =
array_values(array_merge($params,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);

            } else if ($itemsd != NULL && $itemsu != NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $itemsd2 = ['%'.$itemsd.'%'];
                    $itemsu2 = ['%'.$itemsu.'%'];
                    $queryString = $queryString." AND (schoolDistrict LIKE
?) AND (subdivision LIKE ?) AND (address LIKE ? OR MLSNum LIKE ? OR city
LIKE ?)";
                    $params =
array_values(array_merge($params,$itemsd2,$itemsu2,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);	

            } else if ($itemsd != NULL && $itemsu == NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $itemsd2 = ['%'.$itemsd.'%'];
                    $queryString = $queryString." AND (schoolDistrict LIKE
?) AND (address LIKE ? OR MLSNum LIKE ? OR city LIKE ?)";
                    $params =
array_values(array_merge($params,$itemsd2,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);	

            } else if ($itemsd == NULL && $itemsu != NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $itemsu2 = ['%'.$itemsu.'%'];
                    $queryString = $queryString." AND (subdivision LIKE ?)
AND (address LIKE ? OR MLSNum LIKE ? OR city LIKE ?)";
                    $params =
array_values(array_merge($params,$itemsu2,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);	
            }

            $stmt->execute($params);
            $result = $stmt->fetchAll(PDO::FETCH_OBJ);
            $this->pdo = null;
           	
	    return $result;
	}

	/**
	 * Returns rows from the comp table
	 *
	 * Add authorization or any logical checks for secure access to your data 
	 *
	 * 
	 * @return stdClass
	 */
	public function getHalfComps($itemst, $itemmls, $itemouid) {
		
            $itemst2 = [$itemst];
            $itemmls2 = [$itemmls];
            $itemouid2 = [$itemouid];
            
            $queryString = "SELECT origUniqueID, uniqueID, address,
appliances, architecturalStyle, area, areasInterior, auctionCompanyName,
auctionDate, auctionTime, basement, basementDescription, bathsFull,
bathsHalf, bathsTotal, beds, built, "
                                ."city, cool, countyOrParish, dateClosed,
dateListed, disclosures, dom, equipment, exterior, exteriorAmenities,
fireplace, fireplaceDescription, foundation, fuel, garage, "
                                ."heat, interior, latitude, levels,
longitude, lotInformation, lotSize, listAgentFullName, listOfficeName,
mandatoryFee, mandatoryFeeIncludes, mandatoryFeePaid,
masterBedroomDescription, "
                                ."modifiedDT, MLSName, MLSNum, porch, price,
propDescription, propType, schoolDistrict, semiAnnualPropertyTaxAmt,
sqFtMain, sqFtTotal, "
                                ."state, status, subdivision, taxYear,
totalNumOfAcres, township, url, utilityOptions, utilityPrimSewageDisp,
utilityPrimWaterSource, zipcode FROM "
                                ."halfcomp WHERE state = ? AND MLSName = ?
AND origUniqueID = ?";

            $params = array();
            $params = array_values(array_merge($itemst2, $itemmls2,
$itemouid2));
            $stmt = $this->pdo->prepare($queryString);

            $stmt->execute($params);
            $result = $stmt->fetchAll(PDO::FETCH_OBJ);
            $this->pdo = null;
           	
	    return $result;
	}
        
	/**
	 * Counts records in the table
	 *
	 * Add authorization or any logical checks for secure access to your data 
	 *
	 * 
	 */
	public function count($itemst, $itemci, $itempc, $itempbmin, $itempbmax,
$itemapmin, $itemapmax, $itemprmin, $itemprmax, $itemprofit, $itemdom,
$itembu, $itemsd, $itemsu, $itempt, $itembeds, $itembaths, $itemsqft,
$itemdi) {
		
            $itemst2 = [$itemst];
            $itempc2 = [$itempc];
            $itempbmin2 = [$itempbmin];
            $itempbmax2 = [$itempbmax];
            $itemapmin2 = [$itemapmin];
            $itemapmax2 = [$itemapmax];
            $itemprmin2 = [$itemprmin];
            $itemprmax2 = [$itemprmax];
            $itemprofit2 = [$itemprofit];
            $itemdom2 = [$itemdom];
            $itembu2 = [$itembu];
            $itembeds2 = [$itembeds];
            $itembaths2 = [$itembaths];
            $itemsqft2 = [$itemsqft];
            $itemdi2 = [$itemdi];
            $container = explode(',', $itempt);
            $bindStr = implode(",", array_map(function($val) { return "?";
}, $container)); 
            $queryString = "SELECT COUNT(*) AS COUNT FROM half WHERE
(state=?) AND (propCount >= ?) AND "
                            ."(perBelow >= ?) AND (perBelow <= ?) AND
(averagePrice >= ?) AND (averagePrice <= ?) AND (price >= ?) AND (price <=
?) AND "
                            ."(profit >= ?) AND ((UNIX_TIMESTAMP(NOW())*1000
- dateListed)/86400000 <= ?) AND (built <= ?) AND (beds >= ?) AND
(bathsTotal >= ?) AND (sqFtTotal >= ?) AND (propType IN ({$bindStr})) AND (?
IS NULL OR disclosures = ?)";
												   
	    $params = array();
            $params = array_values(array_merge($itemst2,$itempc2,
$itempbmin2, $itempbmax2, $itemapmin2, $itemapmax2, $itemprmin2,
$itemprmax2, $itemprofit2, $itemdom2, $itembu2, $itembeds2, $itembaths2,
$itemsqft2, $container, $itemdi2, $itemdi2));
                                                           
            if ($itemsd == NULL && $itemsu == NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $queryString = $queryString." AND (address LIKE ? OR
MLSNum LIKE ? OR city LIKE ?)";
                    $params =
array_values(array_merge($params,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);

            } else if ($itemsd != NULL && $itemsu != NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $itemsd2 = ['%'.$itemsd.'%'];
                    $itemsu2 = ['%'.$itemsu.'%'];
                    $queryString = $queryString." AND (schoolDistrict LIKE
?) AND (subdivision LIKE ?) AND (address LIKE ? OR MLSNum LIKE ? OR city
LIKE ?)";
                    $params =
array_values(array_merge($params,$itemsd2,$itemsu2,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);	

            } else if ($itemsd != NULL && $itemsu == NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $itemsd2 = ['%'.$itemsd.'%'];
                    $queryString = $queryString." AND (schoolDistrict LIKE
?) AND (address LIKE ? OR MLSNum LIKE ? OR city LIKE ?)";
                    $params =
array_values(array_merge($params,$itemsd2,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);	

            } else if ($itemsd == NULL && $itemsu != NULL) {
                    $itemci2 = ['%'.$itemci.'%'];
                    $itemsu2 = ['%'.$itemsu.'%'];
                    $queryString = $queryString." AND (subdivision LIKE ?)
AND (address LIKE ? OR MLSNum LIKE ? OR city LIKE ?)";
                    $params =
array_values(array_merge($params,$itemsu2,$itemci2,$itemci2,$itemci2));
                    $stmt = $this->pdo->prepare($queryString);	
            }
		
            $stmt->execute($params);
            $result = $stmt->fetchAll(PDO::FETCH_ASSOC);		
            $this->pdo = null;
            $rec_count = $result[0]['COUNT'];
            
            if ($rec_count > 200) {
                    $rec_count = 0;
            } else {
                    $rec_count = 1;
            }

            return $rec_count;
	}	
}
?>



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: RemoteObject, PHP, and Zend

Posted by bilbosax <wa...@comcast.net>.
You guys are not going to believe what the answer was - smart quotes!!  I
swear, I know I am not the best programmer in the world, but I understand
the logic of it, and it looked to me that I was doing everything right.  But
I got the include path by copying it right out of Explorer in Windows, and
pasting it into my php.ini file.  Sadly, it pasted in with smart quotes and
not regular quotes.  A guy on Stackoverflow spotted this somehow because
there were strange symbols around my path in the error code, they look like
little diamonds with question marks in them.

On a further note, I am doing things this way because I am trying to speed
up my database queries and to decrease the amount of data that is being
passed for cost reasons, and came across a blog post by Mihai Corlan that
states that RemoteObject is much much faster using AMF than regular XML
webservices, and in his examples, you have to create an index.php file, a
value object php file, and your service php file to do the work on the PHP
end, and then you have to create a value object actionscript class on the
Flex side to map all of the data to their proper data types.  But this blog
post was written back in 2008, and I don't know how much Flash Builder
evolved since then.

So, my question is this, do you still have to do all of the value object
mapping manually when you are using RemoteObject and AMF, or will Flash
Builder build these classes for you when you connect it to PHP???  My
thinking was that Flash Builder only did this for webservices and
CallResponders, but not for RemoteObject and AMF.  Am I wrong about this??

Thanks



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/