Connection to remote mysql from localhost - php

I have searched the net to no solution for a problem I am facing.
I am working on a codeigniter project which I am running on a localhost Apache Server. For the database, I am attempting to connect from CI's database.php configuration file to connect to a remote server.
The following is my configuration
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'remotedatabase.com';
$db['default']['username'] = 'remote_2102Dev';
$db['default']['password'] = '1q2w3e4r5t';
$db['default']['database'] = 'remote_cs2102';
$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 have tried to connect to the remote Database via mysql workbench 5.5. So that means I have did the configuration correctly at the server side.
Please help me. Is this CI problem or there is something wrong with my settings. Thank you.

Check host entry # remotedatabase.com. It should be % in host
If your PHP version is >= 5.3 set db_debug to false:
$db['default']['db_debug'] = FALSE;

Related

When am running a codeigniter project in local host, it shows error

The problem is am running this project in MAMP php version 8.0.3, and the codeIgniter version is 3, I think it will not support in php version 8.0.3. What is the solution of this problem?
This is my localhost url :http://localhost:8888/mansions/
$db['default']['hostname'] = 'localhost:8888';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'mansions_new_live';
$db['default']['dbdriver'] = 'mysqli';
$db['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;
This is the database configuration details. Is there any solution for this?
I want to run this project in mamp server, its already working in windows server. but it is not working in mamp php version 8.0.3
Your mysql driver is deprecated. To use mysqli driver, add this parameter to your config file located in config/database.php.
$db['default']['dbdriver'] = 'mysqli';

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;

Connect to IBM DB2 from Codeigniter

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;

Categories