Helpful Information
 
 
Category: ColdFusion
PHP within Coldfusion

I am curious about using <cfinclude> to include an external file that has a call to a database and the parsing of the results. I'm wanting to do the call and the parse in PHP, but the page that it will be included on is Coldfusion. Is that possible?

I'm actually wanting to execute this connection, SQL call, and results display:



<?php

// Create the connection file with connection information

$host = "hostname";
$username = "username";
$password = "password";

// Connect to Database

$connection = @mysql_connect($host,$username,$password);
mysql_select_db(database_name,$connection);

$result = mysql_query("SELECT DATE_FORMAT(date,'%b %d, %Y') as article_day, `article_name`, `article_link`, `article_text` FROM `table_name` WHERE `date` <= CURDATE() ORDER BY event_date LIMIT 3");


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<div class="cssarticle">
<div class="headline">'. $row["article_name"] .'</div>
<div class="articledate">'. $row["article_day"].'</div>
<div class="articleintro">'. $row["article_text"].'</div>
<div class="articlelink"><a href="'. $row["article_link"].'">Read More...</a></div>
</div>';
}

mysql_free_result($result);


?>


I'm extremely, extremely new to Coldfusion, so if someone could help show me how to do this, it'd be better than the initial request of PHP in CF.

Thanks so much!!

You have to setup the database connection through ColdFusion Administrator. Once you do that, using the DB is as simple as
<cfquery datasource="database_name" name="example">
SELECT DATE_FORMAT(date,'&#37;b %d, %Y') as article_day, `article_name`, `article_link`, `article_text` FROM `table_name` WHERE `date` <= CURDATE() ORDER BY event_date LIMIT 3
</cfquery>
<cfoutput query="example">
<div class="cssarticle">
<div class="headline">#article_name#</div>
<div class="articledate">#article_day#</div>
<div class="articleintro">#article_text#</div>
<div class="articlelink"><a href="#article_link#">Read More...</a></div>
</div>
</cfoutput>
A lot cleaner than PHP, right?










privacy (GDPR)