php public function __construct if file_exists self DB_NAME this- _db

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
public function __construct(){
if(!file_exists(self::DB_NAME)){
$this->_db = new SQLite3(self::DB_NAME);
$sql = array('CREATE TABLE msgs(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
category INTEGER,
description TEXT,
source TEXT,
datetime INTEGER)',
'CREATE TABLE category(
id INTEGER,
name TEXT)',
'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');
foreach ($sql as $item) {
$this->_db->exec($item);
}
}
$this->_db = $this->_db instanceof SQLite3 ? $this->_db : new SQLite3(self::DB_NAME);
}
?>