0

If you guys could please help, im trying to switch to the new PDO but having a hard time...

Why does this code work:

include ('connect.php');

$sql = "SELECT * FROM GP_2012";
$conn = $DBH->query($sql);

foreach ($conn as $row)
    {
    print $row['Prenom'] . ' ' . $row['Nom'] . '<br>' . 
    'Type: ' . $row['Type'] . '<br>' . 
    'Telephone: ' . $row['Tel'] . '<br>' .
    'Mail: ' . $row['Mail'] . '<br>' .
    'Bateau: ' . $row['Bateau'] . '<br>' .
    '<br><br>';
    }

.

And not this one:

include ('connect.php');

$sql = "SELECT * FROM GP_2012 WHERE Nom LIKE Pageot";
$conn = $DBH->query($sql);

foreach ($conn as $row)
    {
    print $row['Prenom'] . ' ' . $row['Nom'] . '<br>' . 
    'Type: ' . $row['Type'] . '<br>' . 
    'Telephone: ' . $row['Tel'] . '<br>' .
    'Mail: ' . $row['Mail'] . '<br>' .
    'Bateau: ' . $row['Bateau'] . '<br>' .
    '<br><br>';
    }

I tried in PHPMYADMIN and those queries both work, the second one should show one result but instead i get nothing and in my error log i get: Invalid argument supplied for foreach()

user1107703
  • 87
  • 4
  • 12
  • 1
    Set PDO to [throw exceptions on errors](http://us.php.net/manual/en/pdo.error-handling.php). Your problem will become obvious. – DCoder Oct 20 '12 at 11:48

1 Answers1

3

Your sql is wrong.

$sql = "SELECT * FROM GP_2012 WHERE Nom LIKE '%Pageot%'";

You could set the exception mode, then exception will be thrown on error.

Or you need to check the result, if return false, check the error info.

xdazz
  • 158,678
  • 38
  • 247
  • 274