<?php
$host = "localhost";
$dbname = "xxxxx";
$username = "xxxxx";
$password = "xxxxx";
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Veritabanı hatası: " . $e->getMessage());
}
$dosyaAdi = "veriler.txt";
try {
if (file_exists($dosyaAdi)) {
$dosya = fopen($dosyaAdi, "r");
$pdo->beginTransaction();
while (!feof($dosya)) {
$satir = fgets($dosya);
if (!empty($satir)) {
$stmt = $pdo->prepare("INSERT INTO makale (adi) VALUES (:deger)");
$stmt->bindParam(':deger', $satir, PDO::PARAM_STR);
$stmt->execute();
}
}
fclose($dosya);
$pdo->commit();
echo "eklendi";
} else {
echo "Dosya bulunamıyor.";
}
} catch (Exception $e) {
$pdo->rollBack();
echo "eklenmiyor: " . $e->getMessage();
}
$pdo = null;
?>