Question
ColdFusion Script not work with Httpservice
At first I use PHP to generate xml output on page then use
the data to my httpservice with resultformat e4x. Everything is
fine. But now I want to use coldfusion script since I'm planning to
use ColdFusion as my web server. I have this script located on my
server and generate the data in XML file then the XML file is used
in my web, loaded through httpservice.
My PHP code was like this :
<?php
define( "DATABASE_SERVER", "localhost" );
define( "DATABASE_USERNAME", "root" );
define( "DATABASE_PASSWORD", "" );
define( "DATABASE_NAME", "MyCinema" );
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
mysql_select_db( DATABASE_NAME );
$Query = "SELECT * FROM film";
$Result = mysql_query( $Query );
$Return = "<movies>";
while ( $film = mysql_fetch_object( $Result ) )
{
$Return .= "<film><judul>".$film->JUDUL.
"</judul><deskripsi>".$film->DESKRIPSI.
"</deskripsi><genre>".$film->GENRE.
"</genre><produser>".$film->PRODUSER.
"</produser><produksi>".$film->PRODUKSI.
"</produksi><homepage>".$film->HOMEPAGE.
"</homepage><durasi>".$film->DURASI.
"</durasi><url>".$film->URL."</url></film>";
}
$Return .= "</movies>";
mysql_free_result( $Result );
print ($Return);
?>
And now I try to get the same result using coldfusion script. At first I dont write the XML to file, I just cfoutput it just like I do with PHP just print result but it doesnt work out with my HTTPservice. Until I try to write it to XML file then coding my httpservice to read directly from that XML file. here is my coldfusion code.
<cfcomponent>
<cffunction name="a" returnType="Void" output="true" access="remote">
<cfprocessingdirective suppresswhitespace="Yes">
<cfquery name="GetFilm" datasource="myCinemaData">
SELECT b.* FROM playing a, film b
WHERE a.kode_film=b.kode_film AND a.start > <cfqueryPARAM value = "#DateFormat(Now())#"
CFSQLType = "CF_SQL_STRING">
</cfquery>
<cfxml variable="userXML">
<movies>
<cfloop query="GetFilm">
<cfoutput>
<film>
<judul>#GetFilm.JUDUL#</judul>
<deskripsi>#GetFilm.DESKRIPSI#</deskripsi>
<genre>#GetFilm.GENRE#</genre>
<produser>#GetFilm.PRODUSER#</produser>
<produksi>#GetFilm.PRODUKSI#</produksi>
<homepage>#GetFilm.HOMEPAGE#</homepage>
<durasi>#GetFilm.DURASI#</durasi>
<url>#GetFilm.URL#</url>
</film>
</cfoutput>
</cfloop>
</movies>
</cfxml>
</cfprocessingdirective>
<cffile action="write" file="#expandPath(".")#\userXML.xml" output="#userXML#">
</cffunction>
</cfcomponent>
Because I need to create the XML files first I try to execute this coldfusion script first using webservice before I execute my Httpservice but the XML file creation is slower than the execution of my httpservice afterthat so it shows an error that my XML file isn't not available. What can i do? I've tried to show the output using cfoutput and run that script directly on my httpservice just like the way I use print result on PHP but it produce an error.
My PHP code was like this :
<?php
define( "DATABASE_SERVER", "localhost" );
define( "DATABASE_USERNAME", "root" );
define( "DATABASE_PASSWORD", "" );
define( "DATABASE_NAME", "MyCinema" );
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
mysql_select_db( DATABASE_NAME );
$Query = "SELECT * FROM film";
$Result = mysql_query( $Query );
$Return = "<movies>";
while ( $film = mysql_fetch_object( $Result ) )
{
$Return .= "<film><judul>".$film->JUDUL.
"</judul><deskripsi>".$film->DESKRIPSI.
"</deskripsi><genre>".$film->GENRE.
"</genre><produser>".$film->PRODUSER.
"</produser><produksi>".$film->PRODUKSI.
"</produksi><homepage>".$film->HOMEPAGE.
"</homepage><durasi>".$film->DURASI.
"</durasi><url>".$film->URL."</url></film>";
}
$Return .= "</movies>";
mysql_free_result( $Result );
print ($Return);
?>
And now I try to get the same result using coldfusion script. At first I dont write the XML to file, I just cfoutput it just like I do with PHP just print result but it doesnt work out with my HTTPservice. Until I try to write it to XML file then coding my httpservice to read directly from that XML file. here is my coldfusion code.
<cfcomponent>
<cffunction name="a" returnType="Void" output="true" access="remote">
<cfprocessingdirective suppresswhitespace="Yes">
<cfquery name="GetFilm" datasource="myCinemaData">
SELECT b.* FROM playing a, film b
WHERE a.kode_film=b.kode_film AND a.start > <cfqueryPARAM value = "#DateFormat(Now())#"
CFSQLType = "CF_SQL_STRING">
</cfquery>
<cfxml variable="userXML">
<movies>
<cfloop query="GetFilm">
<cfoutput>
<film>
<judul>#GetFilm.JUDUL#</judul>
<deskripsi>#GetFilm.DESKRIPSI#</deskripsi>
<genre>#GetFilm.GENRE#</genre>
<produser>#GetFilm.PRODUSER#</produser>
<produksi>#GetFilm.PRODUKSI#</produksi>
<homepage>#GetFilm.HOMEPAGE#</homepage>
<durasi>#GetFilm.DURASI#</durasi>
<url>#GetFilm.URL#</url>
</film>
</cfoutput>
</cfloop>
</movies>
</cfxml>
</cfprocessingdirective>
<cffile action="write" file="#expandPath(".")#\userXML.xml" output="#userXML#">
</cffunction>
</cfcomponent>
Because I need to create the XML files first I try to execute this coldfusion script first using webservice before I execute my Httpservice but the XML file creation is slower than the execution of my httpservice afterthat so it shows an error that my XML file isn't not available. What can i do? I've tried to show the output using cfoutput and run that script directly on my httpservice just like the way I use print result on PHP but it produce an error.
