How do I resolve Access denied for user ''@'localhost' (using password: NO)?

Asked

Viewed 6,504 times

0

People I am doing here a simple screen that makes a query to the database, the first time I created everything went well, but now I appeared this message "Access denied for user '@'localhost' (using password: NO)". Remembering use of the server in MAMP and my operating system is OSX.

In the index.php file

$db_host = "localhost";
$db_user = "root";
$db_pass = "root";
$db_name = "exemplo01";

in the mdl_usuario.php model

<?php
//função criada que deve ser usada no controller para
    function usuario_listar($conexao){
        $sql = "SELECT id, nome, idade FROM usuario ORDER BY nome";
        $resultado = mysqli_query($conexao, $sql);
        return $resultado;
    }

in controller.php

<?php

$titulo = "Manutenção de Usuários";

//aqui estou fazendo a conexão
$conexao = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

    if(mysqli_connect_errno($conexao)){
        echo "A conexão falhou, erro reportado: ".mysqli_connect_error();
        exit();
    }


    require ("mdl_usuario.php"); //chamando o model onde está as configurações sql

//designar quais serão as views a serem carregadas
//P = Listar, P = Cadastrar e P = Excluir

if(isset($_GET['p'])){ //aqui começamos a verificar os passos
    $passo = $_GET['p'];
}else{
    $passo = null;
}

    switch($passo){
        case"cadastrar"; //como não vamos cadastrar agora
            break; //pulamos
        case"excluir"; //como não vamos excluir pulamos
            break;
        default: //aqui vem o que iremos fazer no momento, que é listar os dados
            $dados = listarDados($conexao);
            require ("view_lista.php");
            break;
    }

//função criada para chamar os dados do database
function listarDados($conexao){
    //$resultado a variavel que vai chamar a função usuario_listar que deve foi criada no modell
    $resultado = usuario_listar($conexao);
//aqui é feito um array para organizar os itens
    $data = array();
//esse array tem um controle através de um while
    while($row = mysqli_fetch_array($resultado)){
        $data[] = array("id"=>$row['id'], "nome"=>$row['nome'], "idade"=>($row['idade']=="")? "--" : $row['idade'] );
    }
    return $data;
}

//esse arquivo sempre deve existir fora do switch pq sempre existira a conexão
@mysqli_close($conexao);
  • Your bank has password even?

  • Has a password that comes as default in MAMP

  • that’s all that appears in the error?

  • Try to leave the password blank... And see the questions in the forum, in the search bar. look if any of these help you:http://answall.com/search?q=qAccess+denied+for+user+%27%40%27localhost%27+%28using+password%3A+NO%29

  • Yeah, just that, and the most amazing thing that first went right, then today when I went to stir it came up.

  • You can reset your root password. Keep in mind that it is not advisable to use root without password. Taken from http://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno

  • Now this worse, I can’t even access phpMyAdmin after I tried to change the root password, which by the way I thought I couldn’t.

  • What happens when you access mysql from the console ?

  • Then @Edilson was able to solve the access problem, because I manually configured the config.inc.php file with the new password that I had created, so it keeps occurring the same error message quoted in the problem when my application tries to connect to the database.

  • You followed in the footsteps here presented ?

  • Yes, and still the same thing, I changed the password and nothing helped, there is no communication.... I will create another test application and see if it will continue the same thing.

Show 6 more comments

1 answer

1


I was able to solve the problem, removed the information from index.php and passed to the controller, the following:

$db_host = "localhost";
$db_user = "root";
$db_pass = "new-root";
$db_name = "exemplo01";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.