内容类型:text / html
致命错误:在 /home/content/18/8476518/html/training/emailOverdo.php 行上的非对象上调用成员函数fetch_object()< b> 88
这是什么意思?!
$courses[] = array('name' => $obj->name, 'length' => $obj->length);
} else {
$query = "SELECT address FROM email LEFT JOIN managers ON (email.id=managers.person_id) WHERE branch_id='".$branch_id."' AND tier='1' AND email.category='2'";
$managers = $db->query($query);
while($manager = $managers->fetch_object())
{
notifyManager($manager->address, $courses, $first_name, $last_name, $day);
}
答案 0 :(得分:2)
您的查询可能会返回null
或false
(取决于您的数据库类)
您的查询错误或者您没有可以选择的数据。
你要检查null
的$经理或错误案例中的预期:
if ($managers !== null) {
//while()
}
答案 1 :(得分:-1)
示例强> 这是你的dbc类
<?php
class dbc {
public $dbserver = 'server';
public $dbusername = 'user';
public $dbpassword = 'pass';
public $dbname = 'db';
function openDb() {
try {
$db = new PDO('mysql:host=' . $this->dbserver . ';dbname=' . $this->dbname . ';charset=utf8', '' . $this->dbusername . '', '' . $this->dbpassword . '');
} catch (PDOException $e) {
die("error, please try again");
}
return $db;
}
function getAllData($qty) {
//prepared query to prevent SQL injections
$query = "select * from TABLE where qty = ?";
$stmt = $this->openDb()->prepare($query);
$stmt->bindValue(1, $qty, PDO::PARAM_INT);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
?>
你的PHP页面:
<?php
require "dbc.php";
$db = new dbc;
$getList = $db->getAllData(25);
foreach ($getList as $key=> $row) {
echo $row['columnName'] .' key: '. $key;
}