::Attention::
  • This blog download stuff contain only links to other sites on the Internet
  • I do not host or upload any file here
  • The article are written in English & Bahasa Malaysia.

Thursday, January 21, 2010

Variables
Coldfusion variables are set with tag. In PHP, a variable is set inside a block of code with a "$" char before the var name. For example:

Coldfusion: myVar = 0>;
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 tag. You have only to specify a datasource name (database you use in your application) and a query name:

myDatasource" name="getUser">
SELECT * FROM USER


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
$db_host="localhost";
$db_name="database_name";
$username="database_username";
$password="database_password";
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// Connection
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);

// 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 tag and add the "query" parameter to specify what query's result you want to display.
getUser">
#name#, #email#, #city#

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


#getUser.name#, #getUser.email#, #getCity.city#


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'] . ',' ;
}
?>




0 comments:

Post a Comment

Categories

Quote of the day

Jom Cuba Resepi

Visitor

free counters

Blog Archive

Investment

Bitcoin | Ethereum | Bitcoin Cash | Tether USDT | Litecoin | Ripple
You're invited!
1. Sign up with my invite link
2. Deposit and buy MYR 250 in BTC (Luno exchange not included)
3. We both get MYR 25.00 free BTC
https://www.luno.com/invite/APY58

Lets Talk

Lowyat.NET

Resources



Your Infos

Followers