Connect to IBM DB2 from Codeigniter - php

I have never worked with DB2 before. I am trying to connect from codeigniter. I have used the following settings in my database config file:
$db['default']['hostname'] = 'ipAddress';
$db['default']['port'] = 'portNumber';
$db['default']['username'] = 'uname';
$db['default']['password'] = 'pword';
$db['default']['database'] = 'myDBName';
//$db['default']['dbdriver'] = 'pdo';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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 it throws the following error:
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\archive\system\database\DB_driver.php
Again, I am totally new to DB2, so in case I need to install anything extra (I assume the driver is already included in my latest CI download) or I need to define a dsn (please let me know how to do that if i require that) please do let me know, will very much appreciate your help.

Yes, you need to install the IBM Data Server Client package, or at least Runtime Client. Download the appropriate driver from http://www-01.ibm.com/support/docview.wss?uid=swg27016878
The manual explains how to configure DB2 access from a PHP application.

You need to add the full connection to the hostname parameter , as the following code
$active_group = 'default';
$active_record = FALSE;
$db['default']['hostname'] = "driver={IBM db2 odbc DRIVER};Database=DBNAME;hostname=localhost;port=50000;protocol=TCPIP;" . "uid=username; pwd=password";
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'DBNAME.SCHEMANAME';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;

Related

Connect with remote mySql from localhost with codeigniter

I have a remote mysql server. Now I am developing a software in Codeigniter integrated with that mysql server. I gave the GRANT ALL to 'user'#'myid' in mysql user. But codeigniter shows the following error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
How can i use remote mysql in my local development environment?
BTW: I use WAMP in windown 7.
Thanks in advance.
EDIT:
Database Configuration:
$db['default']['hostname'] = '198.xxx.xx.66';
$db['default']['username'] = 'root';
$db['default']['password'] = 'xxxxxx';
$db['default']['database'] = 'm000db';
$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;

code igniter error: Unable to connect to your database server using the provided settings. Filename: core/Loader.php Line Number: 346

I'm developing a website application using codeigniter at localhost and then i host it in hawkhost.
At localhost it runs well, but at host there's and error :
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php Line Number: 346
this is my db configuration
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '****';
$db['default']['password'] = '****';
$db['default']['database'] = '****';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;
I know many people already asked this problem but it doesn't seems to solve anything on my case.
changing $db['default']['db_debug'] = TRUE; to false only hide the error but when i tried to get data from query it doesn't return anything.
I also tried to change $db['default']['pconnect'] = FALSE; to true and still doesn't work.
Any help please?
Just change localhost to the local ipaddress i.e. 127.0.0.1 and it will start working.
$db['default']['hostname'] = 'localhost';
to
$db['default']['hostname'] = '127.0.0.1';
In my case setting pconnect to false worked.
$db['default']['pconnect'] = FALSE;
The problem is really due to credentials.
I test it using simple code to check if connection can be made.
The problem is in username, i realize there's additional suffix when using hosting. such as suffix_user
I think the same errors in Core/Loader.php Line Number: 346 has the same solution. make sure the username, password and host are right.
It's solved. Thank you everyone for helping.
Just change
$db['default']['hostname'] = 'localhost';
to
$db['default']['hostname'] = '127.0.0.1';
and voila.
Most of the time this problem happens when codeigniter is in live environment.
That’s why I assumed a domain name ‘(example: domainname.com)’ and after creating a mysql database (example: testDb) and user name (example: testUser) you will find a prefix name automatically added with your mysql database name and user name like ‘domainname_ testDb’ and ‘domainname_ testUser’.
Now in codeigniter /application/config/database.php edit following:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'domainname_ testDb ';
$db['default']['password'] = '*******';
$db['default']['database'] = 'domainname_ testUser';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'domainname_ testDb ';
$db['default']['password'] = '*******';
$db['default']['database'] = 'domainname_ testUser';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;
If anyone else is having this issue, try disabling SE-Linux if you have it enabled. It was causing the connection issues for me, with php 5.4.
Also worth checking is switching
$db['default']['dbdriver'] = 'mysql';
to
$db['default']['dbdriver'] = 'mysqli';
as mysql is depreciated after php 5.5.

Connect to SQL SERVER

i want to connect to sql server
my php version is 5.4 and i have MS SQL Server 2008 R2 and i use PHP Codeigniger 2.4
i change database.php config
$db['default']['hostname'] = '192.168.5.208';
$db['default']['username'] = 'xxx';
$db['default']['password'] = 'xxx';
$db['default']['database'] = 'xxx';
$db['default']['dbdriver'] = 'sqlsrv';
$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;
i download sqlsrv30.exe.
install it in php/ext
i add the following on the php.ini file:
extension=php_sqlsrv_54_ts.dll
i install Native Client 10
i change sqlsrv_driver.php in folder database-driver-sqlsrv to
function db_pconnect() {
//return $this->db_connect(TRUE);
return $this->db_connect(TRUE);
}
i also try add
db['default']['port'] = 1433;
but its still not working. I always encountered the ff. error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\HRM\system\database\DB_driver.php
Line Number: 124
what should i do ? please help
this solves it
change $db['default']['db_debug'] = TRUE; to $db['default']['db_debug'] = FALSE;
and
change $db['default']['pconnect'] = TRUE; to $db['default']['pconnect'] = FALSE;

load Database function doesn't return Codelgniter mysql

I can't connect to mysql database
whatever I use
$autoload['libraries'] = array('database');
or
$this->load->database();
function hangs and never returns
here is my database configurations
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'sms_web';
$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;
What shall i do ??
Solved
Thanks for you efforts
PHP wasn't configured correctly with mysql
PHP.ini file has commented loading mysql extension
just i made sure of the configuration of PHP

CodeIgniter issue with database

I am following a beginner's tutorial for CodeIgniter, but I can't get the view to load correctly because I have a database connection error. I have followed everything step-by-step, and gone through it again several times, but not been able to fix it. Could someone please help me, or at least explain why this is happening?
Here is the database configuration I currently have setup:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'helloworld';
$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;
I've also autoloaded the database library with the following code:
$autoload['libraries'] = array('database');
I would also like to point out that I am using PHP version 5.3.13. I not sure if the version of PHP would affect my code, so I added it anyway.
The exact error I'm getting is:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\wamp\www\CI\system\database\DB_driver.php
Line Number: 124
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root'; // default username if has not been set in phpmyadmin
$db['default']['password'] = ''; //leave it blank if has not been set in phpmyadmin
$db['default']['database'] = 'helloworld'; // this is your database name
$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;
you might have tried to import the project to work space.Instead try to traverse to the project folder through project explorer

Categories