CodeIgniter Forums
can anyone help me ? I m not able to connect database. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: can anyone help me ? I m not able to connect database. (/showthread.php?tid=15364)



can anyone help me ? I m not able to connect database. - El Forum - 02-02-2009

[eluser]bhagatwala[/eluser]
--> I am using wampserver
--> I have saved file in controllers folder.
--> I am able to connect MySQL but not getting connected with Database.
--> Message that i am grtting is "databse not found"
code that i have written is
________________________________________________________________________________________
<html>
<head>
</head>
<body>
<?php
$username = "";
$password = "";
$hostname = "localhost";

$con_str = mysql_connect($hostname, $username, $password)
or die("MySQL not connected");
echo "MySQL Connected<br>";
$con_db = mysql_select_db("demo",$con_str) or die (" Database not found");
?&gt;
&lt;/body&gt;
&lt;/html&gt;
__________________________________________________________________________________________

I have set the config.php file database.php file also


can anyone help me ? I m not able to connect database. - El Forum - 02-02-2009

[eluser]NateL[/eluser]
Check out this helpful tutorial:
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/connect-to-mysql-database.aspx

Also, you are aware that you are asking about procedural programming on a Framework forum.. ? You shouldn't have do do what you're doing with CodeIgniter.


can anyone help me ? I m not able to connect database. - El Forum - 02-02-2009

[eluser]NateL[/eluser]
Also, make sure you created the table named "demo" (without quotes)


can anyone help me ? I m not able to connect database. - El Forum - 02-02-2009

[eluser]the_namdeeW[/eluser]
I would recommend using the built in connection. The whole reason behind using frameworks is to make your life easier.
Just go to /application/config/database.php
This defaults to work with MySQL and just fill in the requirements. Then in your controller just add the following line.
$this->load->database('default');
Good luck!