构造函数不会触发

时间:2012-08-21 22:05:10

标签: php oop constructor

我可能错过了一些明显的东西,但构造函数没有使用新对象触发。我一直把头发拉了几个小时。我确实检查过我从查询中得到了结果。 课程的开头

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;
}

1 个答案:

答案 0 :(得分:3)

public function __construct

你需要两个__