PDO::ERRMODE_EXCEPTION ]); // Auto-migration: if the table does not exist, create it $pdo->exec(<<<'SQL' CREATE TABLE IF NOT EXISTS visitors ( id SERIAL PRIMARY KEY, visited_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); SQL ); } catch (Exception $e) { die("Database connection or migration failed: " . $e->getMessage()); } // Insert a row then count $pdo->exec("INSERT INTO visitors DEFAULT VALUES"); $count = $pdo->query("SELECT COUNT(*) FROM visitors")->fetchColumn(); ?>
You are visitor # = htmlspecialchars($count) ?>