3
I’m performing a Mysql query in this style:
select contents.*, users.* FROM users, contents
Between the two tables there are columns with the same name, and when you pull them with PHP it results the first, but I want both.
Is there any way to get both data from these columns without having to change each column name? I thought I’d put a prefix in when it would work, something like that, but I don’t know if it’s functional.
Have many columns with equal names? the solution via sql is to give an alias (change the name manually in the query). By php see PDO deletes columns with equal names
– rray
There is yes renaming the field names and passing this in your sql: example
select contents.id, contents.descricao as contdescricao
.... and so it goes, to have the unique name for each item of your sql– novic
@rray just renaming even?
– Elaine
@rray saw his option for PHP, but he will do it for all future queries? Because it occurs only in one.
– Elaine
Ai depends on how the code is organized, in case you mark that configuration before the query and end of the method remains or removes it.
– rray
@rray great, see, I use Mysqli, is there a similar function (from setAttribute) for it? I’m searching and still can’t find.
– Elaine
@Elaine a tip I’ll give you that I think would help you understand, if you don’t need all the fields at the junction of
contents
anduser
, the best way to optimize yourSQL
( which is often a performance thief of the system ) and as it is in the response of Allan Andrade, ie specifying what you need and renaming fields that has the same name.– novic
@Virgilionovic, yes I understand, but as there are more than 30 columns and all are used in PHP code, I need to try all options..
– Elaine
@Elaine I fully understand my caveat was whether you were going to use all the fields. There is also a problem there, because 30 fields would not fit a normalization there... !!! are tips ...
– novic
@Virgilionovic I did not understand your question, anything call me on chat. Elaine seems not that option for Mysqli.
– rray
@Virgilionovic I believe it is that and these two consultations are not equivalent.
– rray