* fixed tasklog select

This commit is contained in:
Momchil Bozhinov
2022-08-02 16:21:29 +03:00
parent 32982ab2a8
commit 98f596ee2d
2 changed files with 12 additions and 9 deletions

View File

@@ -15,7 +15,6 @@ class Db {
if (is_null($connect)){
list($file_name, $connect) = $this->prep_connect($place, $database);
if(is_null($file_name) || !file_exists($file_name)){
$this->error=true;
$this->error_message='DB file name not set or not found!';
@@ -38,7 +37,6 @@ class Db {
$this->error=true;
$this->error_message=$e->getMessage(); //'DB Error';
}
}
private function prep_connect($place, $database){
@@ -131,6 +129,9 @@ class Db {
# TODO once tested $values can have a default value of an empty array
function select($sql, $values, $single = false){
if ($this->error){
return array('error' => $this->error, 'info' => $this->error_message);
}
try {
$query = $this->_pdo->prepare($sql);
$i = 1;
@@ -150,8 +151,7 @@ class Db {
}
return $res;
} catch(PDOException $e) {
# TODO: Handling ?
return array();
return array('error' => $this->error, 'info' => $this->error_message);
}
}
@@ -160,6 +160,9 @@ class Db {
}
function insert($sql, $values){
if ($this->error){
return array('error' => $this->error, 'info' => $this->error_message);
}
try {
$this->_pdo->beginTransaction();
$query = $this->_pdo->prepare($sql);
@@ -184,6 +187,9 @@ class Db {
}
function update($sql, $values){
if ($this->error){
throw new Exception($this->error_message);
}
try {
$this->_pdo->beginTransaction();
$query = $this->_pdo->prepare($sql);

View File

@@ -3,11 +3,8 @@
$username=$this->_user_info['username'];
$db=new Db('base','cbsdtaskd');
Utils::clonos_syslog("tasklog: ". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;");
//olevole why array?!
//$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='?' ORDER BY id DESC", array([$username]));
$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='".$username."' ORDER BY id DESC", $username);
$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner=? ORDER BY id DESC", array([$username]));
$html='';
if($res!==false)
@@ -17,7 +14,7 @@ if($res!==false)
if(!empty($res)) foreach($res as $item)
{
Utils::clonos_syslog("tasklog: HTML");
//Utils::clonos_syslog("tasklog: HTML");
$hres=$this->getTableChunk('tasklog','tbody');
if($hres!==false)