So I'm just hypothetically thrilled to be querying my hypothetical database:
$query->select($db->quoteName(array('user_id', 'name')));
I would, however, like the query to look like:
SELECT `user_id` AS `uid`, `name` AS `User-Name`
How the heck do I get the AS in there?
I know this question is 6 months old, so you've probably found an answer or worked around it, but for anyone else who has a similar problem:
If you only want to use an alias for some fields, just pass
null
in the array for the fields you don't want to alias, so for example:would give
It's better to use what Joomla! suggest us.
So, you may have something like this:
Try the following:
Be sure to use the full query as described here:
http://docs.joomla.org/Selecting_data_using_JDatabase
So yours will look something like this:
Please note that I havent tested this query using
AS
so let me know if it works or notMy preferred way is this:
I create an array with the fields I want to select:
In the above array, the keys are used for the db Column names of the query, the values for the aliases, as you can see later in the
$query->select()
.*When you do not need an alias - just set null.
This helps better to control and check what fields I want and how to name them - and is better for maintenance or changes and is portable enough, as I only have to change my
$fields
array according to my needs.Then the Joomla select command can be like:
This will produce the following SQL
SELECT
query:I've got this to work: