Skip to content

Raw query does not add prefix to the table #1146

@alaksandarjesus

Description

@alaksandarjesus

Information

  • Version of Medoo: 2.2
  • Version of PHP: 8.2.12
  • Type of Database: MySQL
  • System: Linux

Describe the Problem
When i try to innerjoin and use db raw to change the date format, it is not appending the db prefix. I have pasted the debugged output.

What actually happened is in my local, I did not have any table prefix. when I moved to production, I added table prefix, and all the requests got down.

Code Snippet
The detail code you are using that causes the problem:

 $select = [
            'pz.title',
            'payment_id',
            'p.amount',
            'paid_at' => $this->db->raw("DATE_FORMAT(p.paid_at, '%d-%m-%Y %H:%i:%s')"),
            'notes',
              'updated_at' => $this->db->raw("DATE_FORMAT(p.updated_at, '%d-%m-%Y %H:%i:%s')"),
            'created_at' => $this->db->raw("DATE_FORMAT(p.created_at, '%d-%m-%Y %H:%i:%s')"),
        ];

        $payouts = $this->db->select('payouts(p)', $join, $select, $where);

Expected Behavior
A clear and concise description of what you expected to happen.
abcd_p.paid_at should be the db->raw

SELECT `abcd_pz`.`title`,
`payment_id`,
`abcd_p`.`amount`,
DATE_FORMAT(abcd_p.paid_at,    
'%d-%m-%Y %H:%i:%s')AS `paid_at`,
`notes`,
DATE_FORMAT(abcd_p.updated_at,
'%d-%m-%Y %H:%i:%s')AS `updated_at`,
DATE_FORMAT(abcd_p.created_at,
'%d-%m-%Y %H:%i:%s')AS `created_at`FROM `abcd_payouts`AS `abcd_p`LEFT JOIN `abcd_puzzles`AS `abcd_pz`ON `abcd_p`.`puzzle_id`=`abcd_pz`.`id`WHERE `user_id`=2 ORDER BY `abcd_p`.`updated_at`DESC LIMIT 10 OFFSET 0


Actual Behavior

SELECT `abcd_pz`.`title`,
`payment_id`,
`abcd_p`.`amount`,
DATE_FORMAT(p.paid_at,
'%d-%m-%Y %H:%i:%s')AS `paid_at`,
`notes`,
DATE_FORMAT(p.updated_at,
'%d-%m-%Y %H:%i:%s')AS `updated_at`,
DATE_FORMAT(p.created_at,
'%d-%m-%Y %H:%i:%s')AS `created_at`FROM `abcd_payouts`AS `abcd_p`LEFT JOIN `abcd_puzzles`AS `abcd_pz`ON `abcd_p`.`puzzle_id`=`abcd_pz`.`id`WHERE `user_id`=2 ORDER BY `abcd_p`.`updated_at`DESC LIMIT 10 OFFSET 0


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions