1

i am new in code igniter, i tried to connect with local db then successfully connected,but while connecting with external db it resulting an error

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/2003): Can't connect to MySQL server on 'xxxxx.gridserver.com' (110)

Filename: mysqli/mysqli_driver.php

Line Number: 202

Backtrace:

File: /var/www/html/restapi/application/libraries/REST_Controller.php
Line: 375
Function: __construct

File: /var/www/html/restapi/application/controllers/Project.php
Line: 26
Function: __construct

File: /var/www/html/restapi/index.php
Line: 292
Function: require_once

i am not familiar with mysql,

i searched more for it, but i have no idea what they speaking about it, is there anything to do for external db connecton

Thank you in advance!

Anvar Pk
  • 122
  • 1
  • 3
  • 18

3 Answers3

2

Check your config->database.php to ensure the $db['default']['hostname'],$db['default']['username'],$db['default']['password'],$db['default']['database'] are set correctly.

Anther possibility is you're trying to connect a MySQL server remotely but the server itself is blocking remote connection. So make sure that you are able to connect your mysql database using the same set of host, username, password through Mysql client software such as "MySQL Workbench"

  • 1
    thank you Tan See Youu , its worked fine, it wasn't allowed by the server, i hosted on server, then its working fine, but i don't know how to allow remote accessing on media template server – Anvar Pk Feb 01 '16 at 10:57
  • 1
    You may try asking for support from your hosting provider. Or if you have ssh access to server, you may try enable it yourself, provided you have permission to open port 3306 to public – Tan See Youu Feb 01 '16 at 12:54
2

As stated by Tan See Youu, it's likely that you may have incorrect credentials in the database.php or indeed named remote connection is being blocked by the server. Though in some cases hosts offer tunnles to be used to allow remote connections through a secured connection. You might want to ask your hosting if they have a SSH tunnel that you could use if they do block direct connections.

killstreet
  • 1,251
  • 2
  • 15
  • 37
2

1.Check your application/config/database.php

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost', // your database machine name, this could have localhost, ip address or domain name.
    'username' => 'yourmysluser',
    'password' => 'yourmysqlpassword',
    'database' => 'yourdb',
    'dbdriver' => 'mysqli',
  1. Check your mysql database, by default remote access to the MySQL database server is disabled for security reason. However, some time you nee to provie remote access to database server from home or a web server. You can enable remote mysql access with mysql console or phpmyadmin or another database tool dependent your host. refer to this :

Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user

and

https://www.youtube.com/watch?v=xXOq9U9fzOo

Community
  • 1
  • 1