0

I am trying to get result from a prepared SELECT query, but i get this error :

PHP Notice: Trying to get property of non-object in /..../php/my.php on line 50

Here is the code :

// Prepared statement
$queryA = $pdo->prepare("SELECT * FROM test WHERE a_id = :id AND created_email = :email");

// Execute statement
$result = $queryA->execute(array(
    'id'        => $id,
    'email'     => $emailAddress
));

if ($result->num_rows > 0) {   // Line 50

while($row = $result->fetch_assoc()) {

...
Thamilhan
  • 13,040
  • 5
  • 37
  • 59
wawanopoulos
  • 9,614
  • 31
  • 111
  • 166

1 Answers1

0

To get the data from a statement, you have basically three options:

  • foreach over PDOStatement object
  • use familiar while with PDOStatement::fetch() method
  • get all the rows in the form of array using PDOStatement::fetchAll() method

So in your case it could be

$stmt = $pdo->prepare("SELECT * FROM test WHERE a_id = :id AND created_email = :email");

// Execute statement
$stmt->execute(array(
    'id'        => $id,
    'email'     => $emailAddress
));

foreach ($stmt as $row) {

if you want to process the data right in place.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345