PHP PDO mySQL查询返回列名和整数

前端之家收集整理的这篇文章主要介绍了PHP PDO mySQL查询返回列名和整数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我对数据库的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] =>操作.我也不想要这些.

他们为什么在这里,我怎么能摆脱他们.

谢谢,

最佳答案
您当前的获取类型必须是:

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

fetch_style

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).

Reference:

原文链接:https://www.f2er.com/mysql/433467.html

猜你在找的MySQL相关文章