使用Medoo在“选择”中使用“别名”

时间:2013-11-17 12:27:17

标签: select frameworks alias

我正在使用Medoo框架。

我需要这个查询:

Select a.name, b.name from section as a left join section as b on(a.idsection=b.section_idfather)

以Medoo格式:

$Data = $database->select("section", 
                [
                "[>]section" => ["idsection" => "section_idfather"]
                ], 
                [
                "section.name",
                "section.name",
                ]
]);

如何以正确的Medoo格式进行此查询?

1 个答案:

答案 0 :(得分:0)

因此,我更改了原始文件,以便为选择列分配ALIAS:

1)加入LINE:127

protected function column_quote_as($ string)     {             return str_replace('。','.',$ string);     }

2)添加LINE:405(原始行)

foreach($columns AS $Columns){
            $columnsTemp =explode('[>]',$Columns);
            $columnsVal = ($columnsTemp[1]!='') ? '`' . $columnsTemp[0] . '` AS \'' . $columnsTemp[1] . '\'':'`' .$columnsTemp[0] . '`';
            $ColumnsEnd[] = $columnsVal;
        }

3)更改LINE:408(原始行)

is_array($ColumnsEnd) ? $this->column_quote_as( implode(', ', $ColumnsEnd) ) :

现在,采用查询的新格式是:

$Data = $database->select("section", 
                [
                "[>]section" => ["idsection" => "section_idfather"]
                ], 
                [
                "section.name[>]SecName",
                "section.name[>]SecNameFather",
                ]
]);