0

我可能遗漏了一些明显的东西,但构造函数没有用新对象触发。我已经拉了几个小时的头发了。我确实检查了我从查询中得到的结果。上课的开始

class OrderDetail {
private $id;
private $product;
private $quanity;
private $price;
private $orderID;
private $noProduction;
private $productName;

public function _construct($orderID, $id = NULL, $product = NULL, $productName = NULL, $quanity = NULL, $price = NULL, $noProduction = NULL){
    $this->id = $id;
    $this->orderID = $orderID;
    echo "check";
    $this->product = $product;
    $this->productName=$productName;
    $this->quanity = $quanity;
    $this->price = $price;
    $this->noProduction = $noProduction;

}

应该创建一个新对象的函数

public static function getOrderDetails($orderID){
    $db=  database_connection::getDB();

    $query = "SELECT tblorder_details.*, tblproduct.product_name
              FROM tblorder_details INNER JOIN tblproduct ON tblorder_details.product_ID = tblproduct.product_ID
              WHERE (((tblorder_details.order_ID)= :orderID))";
    $statement = $db->prepare($query);
    $statement->bindValue(':orderID', $orderID);
    $statement->execute();

    $orderDetails = array();
    foreach ($statement as $row){
        //echo $row["order_ID"];
        $orderDetail = new OrderDetail(
                                    $row["order_ID"],
                                    $row["order_details_ID"],
                                    $row["product_ID"],
                                    $row["product_name"],
                                    $row["quanity"],
                                    $row["price"],
                                    $row["no_production"]);

        $orderDetails[]=$orderDetail;
    }
    return $orderDetails;
}
4

1 回答 1

3
public function __construct

你需要两个__

于 2012-08-21T22:06:43.100 回答