我正在尝试从准备好的SELECT查询中获取结果,但是我收到此错误:
PHP注意:尝试在第50行的/..../php/my.php中获取非对象的属性
以下是代码:
// 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()) {
...
答案 0 :(得分:0)
要从语句中获取数据,您需要basically three options:
PDOStatement
object PDOStatement::fetch()
方法PDOStatement::fetchAll()
方法所以在你的情况下它可能是
$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) {
如果您想正确处理数据。