如何从复制在返回数组每一列的进入停止MySQL的? [英] How do I stop MySQL from duplicating every column's entry in returned arrays?

查看:126
本文介绍了如何从复制在返回数组每一列的进入停止MySQL的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MySQL查询返回与重复的条目数组:数字键和一个里面有相同的数据标签键。这可能是标准的,但它似乎是一种浪费,而一些可能导致问题,如果我打印的值。我的意思是,没有一个巨大的问题,很明显。但我只是好奇,如果我能制止。它似乎没有必要。例如:

My MySQL queries are returning arrays with duplicate entries: numbered keys and labeled keys with the same data inside. This may be standard, but it seems like a waste, and something that could cause problems if I'm printing values. I mean, not a huge problem, obviously. But I'm just curious if I can stop that. It seems unnecessary. For example:

Array(
    [0] => "Ted",
    [first_name] => "Ted",
    [1] => "Schmidlap",
    [last_name] => "Schmidlap"
)

等。

我是pretty新来了很多这一点,所以这可能是一个简单的问题,但谷歌搜索似乎没有任何答案对我来说。任何人都知道发生这种情况的原因吗?我使用PHP的PDO现在,但我之前做直接通过MySQL的功能,同样的事情发生了,所以我认为这是MySQL的互动的副产品。

I'm pretty new to a lot of this, so this may be a simple question, but Googling doesn't seem to have any answers for me. Anyone know the reason this happens? I'm using PHP's PDO now, but I was doing it straight through the MySQL functions before and the same thing was happening, so I assume it's a byproduct of MySQL interaction.

我可以遍历和取消数字的人,因为我不需要他们,但他们没有真正在路上,现在,所以这只是一个额外的步骤。但是,有没有办法根本就没有让他们摆在首位?

I can iterate through and unset the numeric ones, because I don't need them, but they're not really in the way right now, so that's just an extra step. Still, is there a way to simply not have them fetched in the first place?

推荐答案

这取决于你所使用的功能。
有些函数返回两种类型,其他人只能返回其中之一。

That depends on the function you are using. Some functions return both types, others return only one of them.

如果您使用的是 PDOStatement->取,注意的可选$ fetch_style参数的需要。

If you are using PDOStatement->fetch, notice the optional $fetch_style argument it takes.

这篇关于如何从复制在返回数组每一列的进入停止MySQL的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆