我的数据库 PDO 查询将不必要的值返回到数组中。
Array
(
[contentID] => 9
[0] => 9
[type] => operations
[1] => operations
[type_alts] => pages
[2] => pages
[url] => ctt-partners
[3] => ctt-partners
[title] => CTT Partners
[4] => CTT Partners
[subtitle] =>
[5] =>
[online] => 1
[6] => 1
[access] => 0
[7] => 0
[req] => 0
[8] => 0
)
我在寻找不返回相同整数字段和名称的数组。例如 [0] => 9, [1] => operations
。我也不想要这些。
为什么他们在这里,我怎样才能摆脱他们。
谢谢,
最佳答案
您当前的抓取类型必须是:
PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set
鉴于您的要求,它应该是:
PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set
获取样式
Controls how the next row will be returned to the caller. This value must be one of the PDO::FETCH_* constants, defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH).
关于PHP PDO mySQL 查询返回列名和整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19617611/