简体   繁体   English

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

[英]Codeigniter connection to host (a database error)

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 SQLSTATE [HY000] [2002]连接被拒绝

Filename: controllers/Arena.php 文件名:controllers / Arena.php

Line Number: 13 行号:13

I am using codeigniter as the php framework and 000webhost.com for my free hosting needs. 我使用codeigniter作为php框架和000webhost.com来满足我的免费托管需求。

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 和我的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 我第二天坐在这个错误上,这让我发疯

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', 我使用000webhost之前只是将'hostname' => 'files.000webhost.com',更改为phpmyadmin中的IP,这意味着去phpMyAdmin并复制页面中的IP,将其粘贴如下: '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. 或执行此操作您已进入我们的会员区域,进入控制面板,然后单击“ MySQL”图标。 Your MySQL hostname will be listed there. 您的MySQL主机名将在此处列出。

Important! 重要! Never use 'localhost' as your MySQL hostname here or you will get access denied errors! 请勿在此处使用“ localhost”作为您的MySQL主机名,否则您将获得拒绝访问错误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM