Question

This is my first time running Pagoda box. I have a PHP application. It needs to use a MySQL database. I have uploaded all the codes. I have also created a secure tunnel connection. but when I try to connect to the database, there is some problem. I am unable to load the database. It is not even giving me any error.

Here is my code

$this->load->database();
echo 'here';

$db['default']['hostname'] = 'tunnel.pagodabox.com:3306';
$db['default']['username'] = 'xxxx';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = 'blog';
$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;
$db['default']['port'] = 45000;

By the way, my MySQL database is running on port 3306 and tunnel is running in 45000.

Was it helpful?

Solution

Assuming that you are trying to connect to the mysql database in pagodabox from your local machine.

1.Secure Database Tunnel from Your Desktop. You might get something like this if the connection is successful.

Tunnel Established!  Accepting connections on :
-----------------------------------------------

HOST : 127.0.0.1 (or localhost)

PORT : 3307

USER : (found in pagodabox dashboard)

PASS : (found in pagodabox dashboard)

2.Connecting from local codeigniter application to pagodabox mysql

    $this->load->database();
    echo 'here';

$db['default']['hostname'] = '127.0.0.1';

$db['default']['username'] = 'xxxx';

$db['default']['password'] = 'xxxx';

$db['default']['database'] = 'blog';

..

..

$db['default']['port'] = 3307; // This one matches with Port displayed above. 
</pre>

To see the error, open up index.php file and set error reporting E_ALL

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}
error_reporting(E_ALL);

OTHER TIPS

I would recommend a more portable configuration.

Pagodabox exposes the database credentials in the PHP $_SERVER variable and we can benefit like:

if (isset($_SERVER["DB1_HOST"])) {
  // Pagodabox
  $db['default']['hostname'] = $_SERVER["DB1_HOST"].':'.$_SERVER["DB1_PORT"];
  $db['default']['username'] = $_SERVER["DB1_USER"];
  $db['default']['password'] = $_SERVER["DB1_PASS"];
  $db['default']['database'] = $_SERVER["DB1_NAME"];
  $db['default']['port'] = $_SERVER["DB1_PORT"];
} else {
 // my localhost configuration here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top