Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我有此代码,并且我找不到错误。

public  function show(){

$x=NULL;
$owner = $_SESSION['UID'];
$sql = "SELECT
kunde.name AS n1,
rechnung.RechNR AS rnr
FROM  `rechnung`AS  rr
INNER JOIN  `kunde`
ON rr.KID = kunde.KID
WHERE owner = ? ";
$stmt = $this->mysqli->prepare($sql);
$stmt->bind_param("i", $owner);
$stmt->execute();
$result = $stmt->get_result();
while ($obj = $result->fetch_object()) {
 $x[] = $obj;
}

return $x;


}

没有Join的情况下,我得到带有JOIN的结果,但得到了这些消息,但我不知道为什么:在非对象上调用成员函数bind_param()

阅读的谢意。

最佳答案

您必须重写SQL语句,并为字段RechNr使用别名。
您必须使用rechnung.RechNR代替rr.RechNr

$sql = "SELECT
kunde.name AS n1,
rr.RechNR AS rnr
FROM  `rechnung` AS  rr
INNER JOIN  `kunde`
ON rr.KID = kunde.KID
WHERE owner = ? ";


因为您没有使用别名,所以语句的准备确实失败了。

10-01 15:32