How to execute mysql? $sql=DB::select('..'); (for plunig)

Hello,
who could help me?
how I can to execute mysql?

use DB;

$sql = DB::select('select t.id as id, p.name as name FROM tasks t, projects p WHERE … );

Fatal error: Uncaught Error: Class ‘DB’ not found in…

or with mysqli
thanks in advance

You need to use PicoDB as Kanboard does not use mysqli.

The following can be used in any class that extends ‘Kanboard\Core\Base’
Example:

$this->db->table(TaskModel::TABLE)
->columns(‘SUM(time_estimated) AS time_estimated’, ‘SUM(time_spent) AS time_spent’, ‘is_active’)
->eq(‘project_id’, $project_id)
->groupBy(‘is_active’)
->findAll();

2 Likes

Sometimes these kinds of middlewares adds more steps than our basic needs.

I have the following SQL for retrieving the Work Item Age for all cards of a project.

Would you have an idea about how to perform it via PicoDB?

SELECT title, DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()- date_moved), ‘%d’) AS ‘Age’ FROM tasks WHERE project_id = HERE_COMES_THE_PROJECT_ID ORDER BY Age

Thanks!!!

return $this->db
  ->table('tasks')
  ->columns('title', "DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()- tasks.date_moved), '%d') AS WorkItemAge")
  ->eq('project_id', $project_id)
  ->findAll();  

I got it!