Why can not I fetch any data from a mysql table [closed]

-1

What error is there in Foreach?

<?php
    $banco = "mysql:dbnmae=banco;host=localhost";
    $user = "root";
    $senha = "";
    try{
       $conn= new PDO($banco,$user,$senha);
       echo "<h1>conectado com sucesso</h1>";
       $sql = " SELECT * FROM banco";
       $linha =$conn->query($sql);

       foreach($linha as $linhas){
           echo $linhas['nome'];
       }
    }
    catch (PDOException $e){
        echo "<h1>Falha ao conectar</h1>";

       $erro = $e->getCode();
      echo $erro;
    }
    
asked by anonymous 01.07.2018 / 16:35

1 answer

1

It is a writing error. You wrote dbnmae instead of dbname . Change your $banco variable to:

$banco = "mysql:dbname=banco;host=localhost";
    
01.07.2018 / 16:52