Databases in CodeIngniter

1

I'm starting with CodeIgniter and when I make a simple query to the database, it sends me the error that it is trying to access loclhost and not localhost.

I already checked the database configuration and the host name I get localhost.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'codigofacilito',
    'dbdriver' => 'mysqli',
    '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
);

here is the code of my form

<?= form_open("/codigofacilito/recibirdatos")?>
<?php
    $nombre = array(
        'name' => 'nombre',
        'placeholder' => 'Escribe tu nombre'
    );
    $videos = array(
        'name' => 'videos',
        'placeholder' => 'Cantidad videos del curso'
    );
?>
<?= form_label('Nombre: ', 'nombre') ?>
<?= form_input($nombre)?>
<br><br>
<?= form_label('Número de vídeos: ', 'videos') ?>
<?= form_input($videos)?>
<br><br>
<?= form_submit('', 'subir curso') ?>
<?= form_close() ?>

and here the model

   <?php if( ! defined('BASEPATH')) exit('no direct script access allowed');

    class Codigofacilito_model extends CI_Model{
        function __construct(){
            parent::__construct();
            $this->load->database();
        }
        function crearCurso($data){
            $this->db->insert('cursos',array('nombreCurso'=>$data['nombre'], 'videosCurso' => $data['videos']));
        }
    }
?>

and the controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CodigoFacilito extends CI_Controller {
    function __construct(){
        parent::__construct();
        $this->load->helper('form');
        $this->load->model('codigofacilito_model');
    }
    function index(){
        $this->load->library('menu', array('Inicio', 'Contacto', 'Cursos'));
        $data['mi_menu'] = $this->menu->construirMenu();
        $this->load->view('codigoFacilito/bienvenido', $data);
    }
    function holaMundo(){
        $this->load->view('codigoFacilito/headers');
        $this->load->view('codigoFacilito/bienvenido');
    }
    function nuevo(){
        $this->load->view('codigoFacilito/headers');
        $this->load->view('codigoFacilito/formulario');
    }
    function recibirDatos(){
        $data = array(
                'nombre' => $this->input->post('nombre'),
                'videos' => $this->input->post('videos')
        );
        $this->codigofacilito_model->crearCurso($data);
        $this->load->view('codigoFacilito/headers');
        $this->load->view('codigoFacilito/bienvenido');
    }
}
?>

regards and thank you very much for your help

    
asked by Dani Vil 07.07.2018 в 02:58
source

1 answer

0

As I see that route that gives you an error is in the Apache server path, not in the database, it checks your address in

application-> config-> config.php

and change this for yours:

$ config ['base_url'] = ' link ';

    
answered by 15.07.2018 в 06:15