Problem with connection to DB with codeigniter (mysqli) [duplicate]

4

Well, I've done a registration form for newsletter. And while loading the database in autoload['libraries'] , it displays an error

  

Call to undefined function mysqli_init () in /home/softlove/public_html/system/database/drivers/mysqli/mysqli_driver.php on line 136

Can anyone help me?

View-Form:

 <form action="index.php/usuario/newsletter">
                     <div class="form-group">
                         <label for="nome">Nome</label>
                            <input type="text" class="form-control" id="nome" name="nome" placeholder="Nome">
                     </div>
                     <div class="form-group">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" id="email" name="email" placeholder="[email protected]">
                      </div>
                      <div align="center">

                      <button type="submit" class="btn btn-secondary">Cadastrar</button>
                      </div>
                    </form>

Model

<?php
class UsuarioDAO extends CI_Model {

    public function cadastrarDadosUsuario($nome, $email) {
       $this->load->library('database');
        $this->db->query("INSERT INTO signups (signup_nome, signup_email_address) VALUES (?, ?)", array($nome, $email));

        // Inserir código de tratamento de erros...
    }
}

Controller

<?php
class Usuario extends CI_Controller {


    public function newsletter() {
        $this->form_validation->set_rules('nome', 'Nome do usuário', 'required');
        $this->form_validation->set_rules('email', 'E-mail do usuário', 'required');

        if ($this->form_validation->run()) { // Se os dados foram recebidos com sucesso
            $nome = $this->input->post('nome');
            $email = $this->input->post('email');

            /* Carrega a classe que trata da tabela do usuário no banco. 
               Este método pega como referência a pasta application/models.
               Se a classe a ser carregada estiver em algum subdoínio, este deve ser informado também. pe.: $this->load->model('dao/UsuarioDAO');
            */
            $this->load->model('UsuarioDAO');
            $this->UsuarioDAO->cadastrarDadosUsuario($nome, $email);

            // Busque inserir códigos de tratamentos de erros caso o banco gere algum erro.

        } else {
            // código de tratamento de erro...
        }
    }
}

database.php

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'host',
    'username' => 'user',
    'password' => 'senha',
    'database' => 'db',
    '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
);

Autoload.php

$autoload['libraries'] = array('form_validation','database');
    
asked by anonymous 07.07.2016 / 13:15

1 answer

3

I already had this problem, and in case it was the mysqli driver that was not enabled in my php.

See if your driver is enabled in your php.ini, and if you have questions, use the link below for a query.

Codeigniter: fatal error call to undefined function mysqli_init ()

    
15.07.2016 / 13:20