Adobe Dreamweaver Forums



Last 10 THreads :         Word Index importing problem (Last Post : js- - Replies : 9 - Views : 10 )           »          Importing from a database (Last Post : ntsiii - Replies : 2 - Views : 6 )           »          change of state (Last Post : Mainmanian - Replies : 0 - Views : 1 )           »          Could not find the included template (Last Post : Ian Skinner - Replies : 1 - Views : 2 )           »          uploading site (Last Post : hrggroup - Replies : 6 - Views : 7 )           »          linking to a database using xml (Last Post : Twocans - Replies : 18 - Views : 19 )           »          Using AS3 tile list to load video? (Last Post : wendydnew - Replies : 0 - Views : 1 )           »          How to have button in down state as page opens (Last Post : designut - Replies : 2 - Views : 7 )           »          Conditional loop (Last Post : pkonshak - Replies : 0 - Views : 1 )           »          debugger causing browser to crash (Last Post : ntsiii - Replies : 1 - Views : 2 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-25-2008, 08:13 PM
Methylparoben
 
Posts: n/a
Diggs:
Default Help with Flex - PHP - and SQL Server

Good afternoon,

I have been working on this problem for over a week and am at my wit's end. I
am trying to create an application that will allow me and my fellow
statisticians to share code easily. The technologies at my disposal are Flex,
PHP and SQL Server 2005. The web server is IIS. I have downloaded and
installed the PHP driver for SQL Server 2005 and am able to query the database
and generate XML. The problem I'm having is that I can't return the XML from
PHP to Flex.

If I execute the php code in a web browser and view the source, it looks like
XML. I can then cut and paste the exact same code into an xml file and read it
in from the harddisk and the tree will populate. Can anyone please help me? I
don't have flex builder so I it's hard for me to use trace and view what is
going on.

Thanks in advance,

Eric Graves

FLEX CODE:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns="*"
creationComplete="RPCVarDBXML.send()"
>


<mx:Script>
<![CDATA[

]]>
</mx:Script>

<mx:HTTPService
id="RPCVarDBXML" resultFormat="e4x"
url="getXML.php"
useProxy="false">
</mx:HTTPService>

<mx:Tree
id="myTree"
width="50%"
height="100%"
showRoot="true"
labelField="@Label"
dataProvider="{RPCVarDBXML.lastResult.Root.FCRA}"
/>
</mx:Application>





PHP CODE:


<?php

function customError($errno, $errstr)
{
echo "<b>Error:</b> [$errno] $errstr<br />";
echo "Ending Script";
die();
}

set_error_handler("customError");

/* Specify the server and connection string attributes. */

$serverName = "lngminsqld501";

/* Get UID and PWD from application-specific files. */

$uid = "********";
$pwd = "********";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>"ScorModCode");

/* Connect using SQL Server Authentication. */

$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}

/* Query SQL Server for the login of the user accessing the database. */

/* Define the query. */

$tsql = "SELECT 1 as Tag,
NULL as Parent,
RTRIM(varFCRA) as [FCRA!1!Label],
NULL as [Factor!2!Label],
NULL as [Variable!3!Label],
NULL as [Variable!3!Author!ELEMENT],
NULL as [Variable!3!Code!ELEMENT]
FROM VarDB
UNION ALL
SELECT 2 as Tag,
1 as Parent,
varFCRA,
RTRIM(varFactor),
NULL,
NULL,
NULL
FROM VarDB
UNION ALL
SELECT 3 as Tag,
2 as Parent,
varFCRA,
varFactor,
RTRIM(varName),
RTRIM(varAuthor),
varCode
From VarDB
ORDER BY [FCRA!1!Label],[Factor!2!Label],[Variable!3!Label]
FOR XML EXPLICIT, root ('Root')";


/* Execute the query. */

$stmt = sqlsrv_query( $conn, $tsql);
if ( !$stmt )
{
echo "Error in statement execution.<br \>";
die( print_r( sqlsrv_errors(), true));
}

/* Iterate through the result set, printing a row of data upon each
iteration. Note that fields must be accessed in ordinal order. */


if( ($row = sqlsrv_fetch_array( $stmt )) === false )
{
echo "Error in retrieving row.\n";
die( print_r( sqlsrv_errors(), true));
}
$dom = new DomDocument();
$dom->loadXML($row[0]);

echo $dom->saveXML();

/* Free statement and connection resources. */

sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>




XML RETURNED FROM PHP:

<?xml version="1.0" ?>
<Root>
<FCRA Label="FCRA" />
<FCRA Label="FCRA">
<Factor Label="Census">
<Variable Label="testVar3">
<Author>EricG</Author>
<Code>variable example code goes here</Code>
</Variable>
</Factor>
<Factor Label="Derog">
<Variable Label="testVar1">
<Author>EricG</Author>
<Code>variable example code goes here</Code>
</Variable>
</Factor>
</FCRA>
<FCRA Label="Non-FCRA">
<Factor Label="Verification">
<Variable Label="testVar2">
<Author>EricG</Author>
<Code>variable example code goes here</Code>
</Variable>
</Factor>
</FCRA>
</Root>



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-25-2008, 09:02 PM
rtalton
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

yeah, you really need Flex Builder for debugging...
Maybe instead of:
dataProvider="{RPCVarDBXML.lastResult.Root.FCRA}"
...try:
dataProvider="{RPCVarDBXML.lastResult.FCRA}"

You shouldn't have to include the Root element when the resultFormat="e4x".


Reply With Quote
  #3 (permalink)  
Old 11-25-2008, 09:53 PM
Methylparoben
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

Thanks for the suggestion. I have tried every permutation of e4x path notation
I can think of. You're right, you're not supposed to need the root level as
that's supposed to be returned in the result. So you should only need to
reference first level after the root. When I do this and launch the .SWF I get
a completely empty tree.

I think the problem lies somewhere in my understanding of what format Flex
needs returned from a HTTPRequest. It's my understanding that it just needs to
be XML. As far as I can tell, that's what I'm sending it. On the PHP side,
does it have to be cast a special way? Everything I've seen just shows people
using ECHO to output the XML data.

Reply With Quote


  #4 (permalink)  
Old 11-25-2008, 10:33 PM
rtalton
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

Your data from PHP is fine. I used it as-is and had no problems.

See it here:
http://www.anaheimwib.com/_comps/tree/

source view is enabled so you can see what I did.
Hope this helps.
Reply With Quote
  #5 (permalink)  
Old 11-25-2008, 11:33 PM
Methylparoben
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

Thank you for taking the time to assist me. I have been able to reproduce what
you have created with great success, but only when I copy and paste the PHP
output to a file on my harddisk and then read in the file with Flex. My aim is
to have the tree built dynamically from the database based on the XML that PHP
is supposed to return.

It seems the disconnect then is in the HTTPServiceRequest and PHP. Because
even though the PHP output is the exact same XML file you used in your
demonstration, it fails to populate the tree in Flex. Any further assistance
you can provide is greatly appreciated.

Reply With Quote
  #6 (permalink)  
Old 11-25-2008, 11:33 PM
Methylparoben
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

Looking at your code again I see yo have a result function that doesn't do
anything. In my code I don't have a result function at all which makes me
wonder if something is needed in order for the request to work. I will try
using your code tomorrow at work and let you know. Thanks again!

Reply With Quote


  #7 (permalink)  
Old 11-25-2008, 11:33 PM
rtalton
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

the result fhandler is not necessary; I only included it so I could put a line
break there and debug the app and see the XML. I use the result handler because
it's often cleaner to handle the result there instead of assuming the data was
returned ok from the HTTPService call.

Reply With Quote
  #8 (permalink)  
Old 11-25-2008, 11:43 PM
rtalton
 
Posts: n/a
Diggs:
Default Re: Help with Flex - PHP - and SQL Server

One more thing...
Add an fault handler to your HTTPService tag:
<mx:HTTPService
id="RPCVarDBXML" resultFormat="e4x"
url="getXML.php"
useProxy="false"
fault="showFaultEvent(event)">
</mx:HTTPService>
... and in the fault handler, an Alert.show window with the details, like:
public function showFaultEvent(event:FaultEvent):void {
// Handle service fault.
Alert.show(event.fault.faultString, "Error");
}

You may find the answer in the fault event.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 06:50 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk