How connect codeigniter 2 to informix via DSN - codeigniter-2

Hello i have a dsn via odbc connection in my machine. When connect with pure php it´s work.
$_dsn= "informix:DSN=araucaria";
$pdo = new PDO($this->_dsn);
$pdo->setAttribute(3, 2);
How connect codeigniter 2 vía dsn ? My Database CI configuration like this
$db['default']['hostname'] = 'informix:DSN=araucaria';
$db['default']['username'] = 'xxxx';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Help me please!

Related

Connecting oracle 11g with codeigniter

I am trying to connect oracle 11g with codeigniter(V-2.1.4) using xampp(v-1.7.3) . I have changed my config.php to this :
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'system';
$db['default']['password'] = 'root';
$db['default']['database'] = 'orcl';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
and also changed var $dbdriver = 'oci8'; in DB_driver.php file.
But um not able to connect with db. I am getting some sort of database error . It says :
Unable to connect to your database server using the provided settings.
Filename: G:\F\installed\Xampp\xampp\htdocs\codeigniter\system\database\DB_driver.php
Line Number: 124
I am giving line 118 - 127 of DB_driver.php here :
if ( ! $this->conn_id)
{
log_message('error', 'Unable to connect to the database');
if ($this->db_debug)
{
$this->display_error('db_unable_to_connect'); (this is line 124)
}
return FALSE;
}
I want to add that when i try to connect with the following code i am able to see "Succesfully connected with Oracle DB :-)" this message.
conn=oci_connect("system","root","localhost/orcl");
If (!$conn)
echo "Failed to connect to Oracle";
else
echo "Succesfully connected with Oracle DB :-)";
make your database file config as below
host will be IP whre the oracle is installed..
$db['default']['hostname'] = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xx.xx)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XYZ)))';
$db['default']['username'] = "USERNAME";
$db['default']['password'] = "PASSWORD";
$db['default']['database'] = "DATABASE";
$db['default']['dbdriver'] = "oci8";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
try this configuration :
$db['default']['hostname'] = 'localhost/orcl'; // orcl is instance name
$db['default']['username'] = 'system';
$db['default']['password'] = 'root';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'oci8';
and
$db['default']['db_debug'] = FALSE; // default TRUE
this work for me..

Configuring config/database.php file using php script

I have a script in my controller which is as follows:
if($this->db->query("CREATE DATABASE IF NOT EXISTS db_ecommerce"))
{
$sql=file_get_contents('./databse_backup/backup.sql');
foreach (explode(";\n", $sql) as $sql)
{
$sql = trim($sql);
//echo $sql.'<br/>============<br/>';
if($sql)
{
$this->db->query($sql);
}
}
}
It creates a database and then runs a backup sql file.
My issue is that we need to configure the config/database.php file beforehand.
First I want this script to run and after that the database.php file should be changed.
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'db_name';
Since its now for localhost hence,
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'db_name';
An approach would be to have 'template file' in your installation folder like:
ex. database.php
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = '<?php echo $hostname;?>';
$db['default']['username'] = '<?php echo $username;?>';
$db['default']['password'] = '<?php echo $password;?>';
$db['default']['database'] = '<?php echo $database;?>';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '<?php echo $prefix;?>';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
and then you can get the values for db connection (from a form for example) and write the new file in your codeigniter application (application/config/database.php)
ex.
$settings['hostname'] = $this->input->post('hostname');
$settings['username'] = $this->input->post('username');
$settings['password'] = $this->input->post('password');
$settings['database'] = $this->input->post('database');
$settings['prefix'] = $this->input->post('prefix');
$file_contents = $this->load->view('templates/database', $settings, true);
write_file($_SERVER['DOCUMENT_ROOT'].'application/config/database.php', $file_contents);

Not able to access remote database

I am trying to use a remote database for my codeigniter project (I am using WAMP).I get the following error when I try to bring up my controller page:
A Database Error Occurred Unable to connect to your database server using the provided settings. Filename:
C:\wamp\www\Naranpur\system\database\DB_driver.php Line Number: 124
These are my database file settings:
$db['default']['hostname'] = 'something.cs.something.edu';
$db['default']['port'] = '3306';
$db['default']['username'] = 'some_user';
$db['default']['password'] = 'some_pwd';
$db['default']['database'] = 'some_database';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'latin1';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
But when I try to access the database on my localhost with the following settings and give the same url, it works!
$db['default']['hostname'] = 'localhost';
$db['default']['port'] = '3306';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'test';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'latin1';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Could someone please tell me where I might be going wrong?
I think that you need to give the user some_user the privilege to access your database.
from your phpmyadmin got to privilege tab and then edit the privilege for this user.
In the login information section set the host to your IP address or set it to % to allow this user to access from any host.
Can you access to something.cs.something.edu from a mysql client? (to check the connection)

Connect Codeigniter to Oracle 11g

Please help! i can't connect codeigniter to Oracle
I am trying to connect Codeigniter to Oracle 11g, here are my settings
Settings in database.php:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = "//localhost/";
$db['default']['username'] = 'xxxxxxx';
$db['default']['password'] = 'xxxxxxx';
$db['default']['database'] = 'orcl';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Note: I added the C:\instantclient_11_2 to environment variable to PATH.
oracle port number:
oracle hostname: Home-pc
database name: orcl
Only when I run my CodeIgniter login code it shows this error message:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: D:\xampp\htdocs\ci\system\database\DB_driver.php
Line Number: 124
But I can connect to Oracle when I run a simple php code like:
<?php
$conn = oci_connect("xxxxxx", "xxxxxx","");
if (!$conn) {
echo "Not connected!";
}
else
echo "yahooooooooo!!!!!!!!!!";
?>
Result:
yahooooooooo!!!!!!!!!!
In your config's database.php make the following changes
$active_group = 'default';
$active_record = TRUE;
$tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))';
$db['default']['hostname'] = $tnsname;
$db['default']['username'] = 'XXXXXX';
$db['default']['password'] = 'XXXXX';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
change default to XE
$active_group = 'XE';
$active_record = TRUE;
$tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))';
$db['XE']['hostname'] = $tnsname;
$db['XE']['username'] = 'XXXXXX';
$db['XE']['password'] = 'XXXXX';
$db['XE']['database'] = '';
$db['XE']['dbdriver'] = 'oci8';
$db['XE']['dbprefix'] = '';
$db['XE']['pconnect'] = TRUE;
$db['XE']['db_debug'] = TRUE;
$db['XE']['cache_on'] = FALSE;
$db['XE']['cachedir'] = '';
$db['XE']['char_set'] = 'utf8';
$db['XE']['dbcollat'] = 'utf8_general_ci';
$db['XE']['swap_pre'] = '';
$db['XE']['autoinit'] = TRUE;
$db['XE']['stricton'] = FALSE;
try to do this changes
change the hostname to http://localhost:1521:orcl
you are given database name as orcl , by default orcl is default instance id.
try to create new user or database and change it in to the configuration database.
Make sure php_oci8_11g.dll extension is loaded in php.ini

CodeIgniter MultiDatabse connect error

I see a lot of method/tutorial to connect multi database in CodeIgniter? Still far far away with me. Some one provide me to connect multi database in CI. This is my using way i was found it in a blog. pardon me, i don't recognize the blog address.
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'vk_global';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
//add alternate database settings
$db['wow']['hostname'] = 'localhost';
$db['wow']['username'] = 'root';
$db['wow']['password'] = 'root';
$db['wow']['database'] = 'auth';
$db['wow']['dbdriver'] = 'mysql';
$db['wow']['dbprefix'] = '';
$db['wow']['pconnect'] = TRUE;
$db['wow']['db_debug'] = TRUE;
$db['wow']['cache_on'] = FALSE;
$db['wow']['cachedir'] = '';
$db['wow']['char_set'] = 'utf8';
$db['wow']['dbcollat'] = 'utf8_general_ci';
$db['wow']['swap_pre'] = '';
$db['wow']['autoinit'] = TRUE;
$db['wow']['stricton'] = FALSE;
i was call it with this code
$DB2 = $this->load->database('auth',true);
and i was insert a simple row with this code
$this->$DB2->insert('events_grouptable',$data);
i got this error You have specified an invalid database connection group.
how should i solve this error?
$DB1 = $this->load->database('default', TRUE);
$DB2 = $this->load->database('wow', TRUE);
You need to set which db to use with which group otherwise the alternative does not work as
$active_group = 'default';
More details are here http://ellislab.com/codeigniter/user-guide/database/connecting.html

Resources