Try with this:

$columnsVal = ($columnsTemp[1]!='') ? '`' . $columnsTemp[0] . '` AS \'' . $columnsTemp[1] . '\'':'`' .$columnsTemp[0] . '`';