<?php

$fn = fopen('news-utf8.txt', 'r') or die('I can not open the file.');

$db = new SQLite3('aol.db');
$db->exec("CREATE TABLE IF NOT EXISTS news(id INTEGER PRIMARY KEY ASC, author TEXT, category INTEGER, title TEXT, content TEXT)");
$stm = $db->prepare("INSERT or REPLACE INTO news(id, author, category, title, content) VALUES (?, ?, ?, ?, ?)");
$stm->bindParam(1, $id);
$stm->bindParam(2, $author);
$stm->bindParam(3, $category);
$stm->bindParam(4, $title);
$stm->bindParam(5, $content);

while(!feof($fn))  {
    $rLine = fgets($fn);
    if ($rLine) {
	    $arrNews = explode('|', $rLine);

		$id 		= intval($arrNews[0]);
		$author 	= $arrNews[1];
		$category 	= intval($arrNews[4]);
		$title 		= $arrNews[2];
		$content 	= $arrNews[3];
		
		$stm->execute();
    }
 }

fclose($fn);
