There's no much difference internally. Both ordinal positions and column names are available in the result set metadata within the MySQL client API, regardless.
Regarding usage, both can be handy in different circumstances. Referencing columns by name is more mnemonic, results in (semi-) self-documenting code, allows you to change the position or number of columns in the query without breaking your code, etc.
But fetching by ordinal is hand too sometimes. For example:
SELECT u.name, d.name FROM user u JOIN department d USING (dept_id)
Now you have two columns with the same name in the result set. If you fetch an associative array, one overwrites the other because an assoc array can only have one value per key. So $row["name"]
is one of the names, and you don't necessarily know which it's going to be.
SELECT d.name, COUNT(*) FROM user u JOIN department d USING (dept_id) GROUP BY dept_id
Now you have a column that has no alias, and depending on the RDBMS brand you use, it could invent a funny-looking alias automatically, or else just use the whole expression as the key for the assoc array. So it's nice to be able to use ordinal position instead of column name in this case.
(It's funny how my writing style becomes more informal and chatty when I'm listening to the StackOverflow podcast while I'm writing.)