Home > Back-end >  PHP Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database sele
PHP Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database sele

Time:07-16

I have a problem with PDO, and I see absolutely nowhere he comes. I can not question my MySQL database. Just to test I used the following code (having quite sour previously configured the parameters for the connection:

protected function createMigrationsTable()
{
    $this->pdo->exec("CREATE TABLE IF NOT EXISTS migrations (
        id INT AUTO_INCREMENT PRIMARY KEY,
        migration VARCHAR(255),
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )  ENGINE=INNODB;");
}

The connection is made correctly with MySQL but after migration, I get this error:

error

CodePudding user response:

CHECK the DSN string. For MySQL it should look like this:

mysql:host=hostname_or_ip;port=XXXX;dbname=name_of_db

or after establishing connection, make:

  $this->pdo->exec("USE database_name");
  •  Tags:  
  • php
  • Related