-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
50 lines (44 loc) · 1013 Bytes
/
process.php
File metadata and controls
50 lines (44 loc) · 1013 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require_once 'iprocess.php';
/**
*
*/
class Process extends Database implements IProcess
{
private $textID = false;
function __construct(){
parent::__construct();
}
function processText($text)
{
$this->_add_to_database($text);
return $this->textID;
}
function fetchText($textID)
{
return $this->_fetch_from_database($textID);
}
private function _add_to_database($text){
$tid = $this->genTextID();
try{
$sth = $this->pdo->prepare("INSERT INTO kt_texts (textid, textcontent, timeadded) VALUES (?, ?, ?)");
if($sth->execute([$tid, $text, time()])) $this->textID = $tid;
}
catch(PDOException $ex){}
}
private function _fetch_from_database($textID){
try{
$sth = $this->pdo->prepare("SELECT * FROM kt_texts WHERE textid = ? LIMIT 1");
$sth->execute([$textID]);
return $sth->fetchObject();
}
catch(PDOException $ex){
return [];
}
}
private function genTextID(){
$spice = "ketewa#";
$uniqID = uniqid("$spice");
return hash("crc32", $uniqID);
}
}