dongyue1988 2017-04-18 16:46
浏览 50
已采纳

Codeigniter与主机的连接(数据库错误)

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

  • 写回答

1条回答 默认 最新

  • dongyu1125 2017-04-18 16:53
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景