PHP Databases PDO connections

后端 未结 1 2005
情书的邮戳
情书的邮戳 2020-12-12 06:30

Hey guys im having a little trouble with the PDO in php as the error it is returning is an undefined index. The code for the function and query and return of result is this:

1条回答
  •  旧巷少年郎
    2020-12-12 06:46

    fetchAll returns all results (potentially multiple rows) in a multidimensional array:

    array(
        0 => array(/* first row */),
        1 => array(/* second row */),
        ...
    )
    

    That's why the array doesn't have a direct index 'name', it needs to be [0]['name'].
    Or you shouldn't fetchAll, just fetch.

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