Coldfusion VS PHP

Coldfusion variables are set with <cfset> tag. In PHP, a variable is set inside a <?php …?> block of code with a “$” char before the var name. For example:

Coldfusion: <cfset myVar = 0>
PHP: <?php $myVar = 0?>

Differences between URL variables:

Coldfusion: #URL.myVar#
PHP: $_GET[‘myVar’];

Differences between POST variables:

Coldfusion: #POST.myVar#
PHP: $_POST[‘myVar’];

Execute a query
Coldfusion queries are “beautiful” šŸ™‚ and very simple to define with <cfquery> tag. You have only to specify a datasource name (database you use in your application) and a query name:

<cfquery datasource=”myDatasource” name=”getUser”>

If you use PHP, when you add a query, you have to include in your page all the parameters to connect to database. I suggest to read this post to have more info about this topic. A tipical query in PHP is structured in this way:

// Connection’s Parameters
// Connection

// Query
$sql = ‘SELECT * FROM USER’;
$getUser = mysql_query($sql);

How you can see, I defined a variable $sql (with the query SQL code). mysql_query($sql) execute the query.

Query results
After the execution of a query you would show the query results. With coldfusion you ca use <cfouptut> tag and add the “query” parameter to specify what query’s result you want to display.

<cfoutput query=”getUser”>
#name#, #email#, #city#

You can also use this dotted code if inside a <cfoutput> code you want to display results from different queries:


With PHP you have use mysql_fetch_array() method inside a while statement:

while ($row = mysql_fetch_array($getUser)){
echo $row[‘name’] . ‘,’ ;
echo $row[’email’] . ‘,’ ;
echo $row[‘city’] . ‘,’ ;

I hope this post about this topic can be useful to all PHP/Coldfusion beginner developers.

got this @

Leave a Reply