4

A Codeigniter project(in windows) is required to connect with a Remote Mysql Database(in linux server). here is my database.php configuration.

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'xxx.xxx.x.xxx';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database';
$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;

and it gives an error

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: *:\****\***\htdocs\project\system\database\DB_driver.php

Line Number: 124

but i can access the remote mysql database via Phpmyadmin and Heidisql using the same username and password. (all privilages granted)

Here is Remote Database configuration

Server version: 5.0.95
Protocol version: 10
Server: Localhost via UNIX socket
MySQL charset: UTF-8 Unicode (utf8)
MySQL client version: 5.0.95
Used PHP extensions: mysql

Any help would be greatly appreciated

Shifana Mubi
  • 197
  • 1
  • 3
  • 17
  • Take a look at this, [link](http://stackoverflow.com/questions/8107449/connecting-to-a-remote-database-through-codeigniter). It may be due to the port configuration. – ArrowHead Feb 05 '16 at 13:30
  • If you are using codeigniter 3, the mysql driver has been removed. Try with pdo or mysqli instead. See : https://www.codeigniter.com/user_guide/database/configuration.html#explanation-of-values – AdrienXL Feb 05 '16 at 14:40
  • @AdrienXL Deprecated, not removed - that's deffinately not the problem here. But otherwise, yeah - go with mysqli. – Narf Feb 05 '16 at 22:54
  • Also, judging by the line number shown in that error message - the OP is using 2.x. – Narf Feb 05 '16 at 22:56
  • changed the `$db['default']['dbdriver'] = 'mysql';` to `$db['default']['dbdriver'] = 'mysqli';` but no improvements. when tried with `pdo` it returns `Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name'` – Shifana Mubi Feb 06 '16 at 04:30

3 Answers3

1

I faced the same issue before a couple of months ago when connecting to the remote mysql server in linux.

I tried this in mysql via PHPMYADMIN

SHOW VARIABLES LIKE 'old_passwords' and it says me ON

it means that old_passwords=1 in my.cnf file in the server mysql configuration.

Solution for this problem is by updating the password for the corresponding user

Reference : Error: mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication

Community
  • 1
  • 1
Akhil P M
  • 174
  • 1
  • 2
  • 13
  • 1
    Just tried this, no effect in codeigniter. it still return the same error that i mentioned on the question. but when i tried with a normal php programs it returns `Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication...` – Shifana Mubi Feb 06 '16 at 09:44
  • Update the database password again with nothing. and then try to connect with no password. – Akhil P M Feb 06 '16 at 09:50
0

Not sure if this would help, but I did encounter similar issue before.

$db['default']['dbdriver'] = 'mysqli';

instead of

$db['default']['dbdriver'] = 'mysql';
duduwe
  • 888
  • 7
  • 16
  • @ShifanaMubi, that is unfortunate. I checked your settings based on my working projects just to make sure and they should work. So, you probably are left to consider 1.) firewall? 2.) correct credentials (host, user, pwd). – duduwe Feb 06 '16 at 09:43
0

See if this works

Create a user with all privilages, Remember to set host to %

Edit mysqld.cnf and set "bind-address = 0.0.0.0" (may be /etc/mysql/mysql.conf.d/mysqld.cnf)

Restart mysql

Kavinda Jayakody
  • 705
  • 1
  • 13
  • 25