Pdoexception error

Asked

Viewed 131 times

-2

Hello, I’m having difficulties in hosting a php system, initially I developed with xampp (localhost), however, when host is not making the Mysql connection for what I understood..

Error: Exception 'Pdoexception' with message 'SQLSTATE[3D000]: Invalid'

How I’m making the connection:

<?php
    try{
        $conexao = new PDO('mysql:host=ipdomeuhost;nomebd', nomeuser, senha);
        $conexao ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }catch(PDOException $e){
        echo 'ERROR: ' . $e->getMessage();
    }
?>

I created the database in the hosting, including the user and password, but I can’t solve this error, someone can help?

1 answer

3


Your connection is incorrect. Use the connection below.

try {
  $conn = new PDO('mysql:host=localhost;dbname=meuBancoDeDados', $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

Browser other questions tagged

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