Jesse Dijkstra
Jesse Dijkstra

Reputation: 130

PHP PDO Fetching Results

I'm trying to simply echo results out on the screen from my database. I'm quite new with PDO, and I've been searching on this site for an answer that works, but have found none so far.

$results = $MyConnection->prepare("SELECT Antwoord1, Antwoord2, Antwoord3 FROM CCOpendag ");
$results->execute();
$foundResults = $results->fetchAll(PDO::FETCH_ASSOC);

echo $foundResults;

This piece of code simply echoes out 'Array'. What I want to achieve is that I get the results from these 3 columns and display them on the screen. If somebody could help me out, that would be amazing.

Upvotes: 1

Views: 106

Answers (3)

anand
anand

Reputation: 371

$foundResults is an array with all the records . You can view the array by using print_r($foundResults).

Or it will be better if you use a loop to read each rows while($foundResults=$results>fetch(PDO::FETCH_ASSOC)) {

echo $foundResults['Antwoord1'].$foundResults['Antwoord2'];

}

Upvotes: 0

brigantaggior
brigantaggior

Reputation: 108

print_r($foundResults) or var_dump($foundResults)

Upvotes: 1

patricksweeney
patricksweeney

Reputation: 4022

It shows "Array" because you need to iterate over the results, and not simply just echo it out. Use var_dump or print_r and you should see the array; you can then loop out the results as you wish - var_dump will just show you the whole array.

Upvotes: 1

Related Questions