0

I am having a problem with PDO::FETCH_ASSOC option when fetching results from database. I am getting array that has numbers as indexes instead of row names. Why is this happening?

$result = $resultSet->fetch_all(PDO::FETCH_ASSOC);

Result:

array(5) { [0]=> array(3) { [0]=> int(1) [1]=> string(15) "example1" [2]=> NULL } [1]=> array(3) { [0]=> int(2) [1]=> string(10) "example2" [2]=> int(1) } [2]=> array(3) { [0]=> int(3) [1]=> string(17) "example3" [2]=> int(1) } [3]=> array(3) { [0]=> int(4) [1]=> string(3) "example4" [2]=> int(1) } [4]=> array(3) { [0]=> int(5) [1]=> string(9) "example5" [2]=> NULL } } 
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

2

fetch_all() is not a method of PDO, but of MySQLi.

You might want to use :

$result = $resultSet->fetch_all(MYSQLI_ASSOC);
Syscall
  • 19,327
  • 10
  • 37
  • 52