SQLSTATE[3D000]:1046 - No database selected

Ich versuchte, führen Sie eine SQL-CREATE-Befehl mit php, aber ich habe dieses problem:

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

Kann ich WIRKLICH nicht wissen, wo ist das problem, bitte könnten Sie mir helfen?

Dies ist das Skript:

<?php

include 'connessione.php';

try {
    $sql = 'CREATE TABLE joke (
            id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
            joketext TEXT,
            jokedate DATE NOT NULL 
            ) DEFAULT CHARACTER SET uft8 ENGINE=InnoDB';
    $pdo->exec($sql);
} catch (PDOException $e){
    $output = 'Errore nella creazione della tabella joke: ' . $e->getMessage();
    include 'output.html.php';
    exit();
}

$output = 'Tabella creata con successo.';
include 'output.html.php';

?>

Und hier die "connessione.php" Datei:

<?php

$host = 'host=localhost'; 
$mysql_user = 'root';
$mysql_password = '';
$database = 'php';

try { 
    $pdo = new PDO('mysql:$host;dbname=$database', $mysql_user, $mysql_password); 
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
} catch (PDOException $e) {
    $output = 'Impossibile connettersi al database: ' . $e->getmessage();
    include 'output.html.php';
    exit();
}

?>

Ich habe in der "connessione.php die" Datei-und die Verbindung zur Datenbank nicht richtig. Auch ich überprüfte user-Privilegien und root hat alle Rechte auf "php" Datenbank... Was ist das problem?!

InformationsquelleAutor Davide Scanu | 2014-12-12
Schreibe einen Kommentar