How to connect database in ColdFusion
Step 1:
Open any broswer and enter
the following url
Step 2:
Give your ColdFusion admin login
password.
Step 3:
Step 4:
Click Data & Service -> Data
Source -> right side show data source screen
Step 5:
Enter your Data Source Name
and Driver selection(MySql(4/5), oracle and SQL-server) any one
driver seleted and then click add button
Step 6:
Enter Data base name, server,
username, password and Description will enter. Here showing details
Step 7:
Click Submit button. Now status is ok
so connection is established.
Following query execute in your
database(codeigniter)
CREATE TABLE IF NOT EXISTS `employee` (
`id` int(11) NOT NULL,
`name` varchar(30) NOT NULL,
`city` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ;
INSERT INTO `employee` (`id`, `name`, `city`) VALUES
(1, 'sathiyaraj', 'chennai'),
(2, 'KUAMR', 'VELLORE'),
(3, 'raj', 'madrass'),
(4, 'bala', 'madurai'),
(5, 'selvamani', 'vellupuram'),
(6, 'kumar', 'test'),
(7, 'senthil', 'thindukal');
Step 8:
Open Notepad and paste the following
code
<cfquery name="EmpList"
datasource="mysqlcon" username="root"
password="">
select * from employee
</cfquery>
<cfoutput query="EmpList">
#EmpList.id#, #EmpList.name#,
#EmpList.city#<br>
</cfoutput>
Save the file in any name and
run it.
Step 9:
Output will show like
1,
sathiyaraj, chennai
2, KUAMR, VELLORE
3, raj, madrass
4, bala, madurai
5, selvamani, vellupuram
6, kumar, test
7, senthil, thindukal
2, KUAMR, VELLORE
3, raj, madrass
4, bala, madurai
5, selvamani, vellupuram
6, kumar, test
7, senthil, thindukal
Comments
Post a Comment