0

I got this error when I was uploading my files to my host server, particularly when I started uploading my models.

SQLSTATE[HY000] [2002] Connection refused

Filename: controllers/Arena.php

Line Number: 13

I am using codeigniter as the php framework and 000webhost.com for my free hosting needs.

example of my model

<?php
class Image_model extends CI_Model{

    function get_image_data(){
        $this->load->database();

        $this->db->select('nuotrauka,id,kalba');
        $this->db->where('kalba', 'lt');
        $query = $this->db->get('events');

        return $query->result();
    }
}

my controller

<?php
class Arena extends MY_Controller{

    public function display(){

        $this->load->model('Image_model');
        $data['images'] = $this->Image_model->get_image_data();

        $this->load->view('includes/head');
        $this->load->view('includes/header', $data);
        $this->load->view('includes/footer');
    }
}

and my database.php

    $db['default'] = array(
    'dsn'  => 'mysql:host=files.000webhost.com; dbname=id692581_name; charset=utf8;',
    'hostname' => 'files.000webhost.com',
    'username' => 'id692581_username',
    'password' => 'password',
    'database' => 'id692581_name',
    'dbdriver' => 'pdo',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

I'm sitting on this error for the second day and it is making me crazy

2
  • 2
    and now you SHALL at once go and change the database username and password if those are the actual ones. Commented Apr 18, 2017 at 16:54
  • I would autoload the database in config/autoload.php saves you putting $this->load->database(); every where Commented Apr 18, 2017 at 22:11

1 Answer 1

1

i used 000webhost before just change 'hostname' => 'files.000webhost.com', to the ip in phpmyadmin what i mean go to phpMyAdmin and copy the ip in page in paste it like this: 'hostname' => '164.50.60.70',

OR do this You have go to our members' area, enter the control panel and click on the 'MySQL' icon. Your MySQL hostname will be listed there.

Important! Never use 'localhost' as your MySQL hostname here or you will get access denied errors!

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry instructions not very clear there is no members area nor control panel and definitely no mysql icon(i've never seen mysql words used in this website to begin with)
It seems I cant find anything so I'll just use localhost this time
i am trying to connect but hostname is giving error
from where I get hostname, i m using free account @Abanoub Makram

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.