Warning: SQLite3::exec(): table msgs has no column named categories in C:\Users\User\Desktop\OpenServer\domains\localhost\php-3\news\NewsDB.class.php on line 45
table msgs has no column named categories
Как исправить эту ошибку?
45 строка вот:
$this->_db->exec($sql) or die($this->_db->lastErrorMsg());
Остальной код:
<?php
require 'INewsDB.class.php';
class NewsDB implements INewsDB {
protected $_db;
const DB_NAME ='C:\Users\User\Desktop\OpenServer\domains\localhost\php-3\news.db';
function __construct(){
if(is_file(self::DB_NAME)){
$this->_db = new SQLite3(self::DB_NAME);
}
else{
$this->_db = new SQLite3(self::DB_NAME);
$sql = "CREATE TABLE msgs(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
category INTEGER,
description TEXT,
source TEXT,
datetime INTEGER)";
$this->_db->exec($sql) or die($this->_db->lastErrorMsg());
$sql = "CREATE TABLE category(
id INTEGER,
name TEXT)";
$this->_db->exec($sql) or die($this->_db->lastErrorMsg());
$sql = "INSERT INTO category(id, name)
SELECT 1 as id, 'Политика' as name
UNION SELECT 2 as id, 'Культура' as name
UNION SELECT 3 as id, 'Спорт' as name";
$this->_db->exec($sql) or die($this->_db->lastErrorMsg());
}
}
function __destruct(){
unset($this->_db);
}
function clearStr($data){
$data = trim(strip_tags($data));
return $this->_db->escapeString($data);
}
function clearInt($data){
return abs((int)$data);
}
function saveNews($title, $category, $description, $source){
$dt = time();
$sql = "INSERT INTO msgs(title, categories, description, source, datetime)
VALUES ('$title', '$category', '$description', '$source', $dt)";
$this->_db->exec($sql) or die($this->_db->lastErrorMsg());
}
function getNews(){}
function deleteNews($id){}
}
?>