PDO prepared statement fetch() returning double results

前端 未结 1 1388
独厮守ぢ
独厮守ぢ 2020-12-03 22:23

I have a script that is outputting to a CSV file. However, even though there is currently one row in the database, the output I\'m getting is echoing out each column from ea

相关标签:
1条回答
  • 2020-12-03 22:35

    You should say to PDO, that you want only an associative array or a numbered array:

    while ($rows_get_rows = $result_get_rows->fetch(PDO::FETCH_ASSOC)) 
    

    to get an associative array or

    while ($rows_get_rows = $result_get_rows->fetch(PDO::FETCH_NUM)) 
    

    to get an array indexed by the column number

    from PDOStatement::fetch

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

    PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set

    PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set

    0 讨论(0)
提交回复
热议问题