Welcome Guest, Not a member yet? Register   Sign In
[Active Record] Select AS Backticks problem
#6

[eluser]Azhari Harahap[/eluser]
Finally get it working with little addition to the AR class.

Code:
// --------------------------------------------------------------------

    /**
     * Select AS
     *
     * Generates the SELECT(field AS) portion of the query
     *
     * @access    public
     * @param    string
     * @return    object
     */
    function select_as($select = '', $alias = '')
    {        
        if ( ! is_string($select) OR $select == '')
        {
            $this->display_error('db_invalid_query');
        }

        if ( ! is_string($alias) OR $alias == '')
        {
            $this->display_error('db_invalid_query');
        }        

        $sql = $this->_protect_identifiers(trim($select)).' AS '.$this->_protect_identifiers(trim($alias));

        $this->ar_select[] = $sql;
        
        if ($this->ar_caching === TRUE)
        {
            $this->ar_cache_select[] = $sql;
            $this->ar_cache_exists[] = 'select';
        }        

        return $this;
    }

And then you can do this:
Code:
$this->db->select_as('Name', 'GroupName');

It will produce:
Code:
SELECT `Name` as `GroupName` FROM (`pbk`)


Messages In This Thread
[Active Record] Select AS Backticks problem - by El Forum - 03-05-2011, 12:04 PM
[Active Record] Select AS Backticks problem - by El Forum - 03-08-2011, 12:48 AM
[Active Record] Select AS Backticks problem - by El Forum - 03-08-2011, 01:28 AM
[Active Record] Select AS Backticks problem - by El Forum - 03-08-2011, 04:53 AM
[Active Record] Select AS Backticks problem - by El Forum - 03-11-2011, 03:46 AM
[Active Record] Select AS Backticks problem - by El Forum - 03-11-2011, 03:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB