我是这个网站的新手,但我的代码出了问题。
我从PHP开始使用OOP,并且我正在努力学习get和set。
我用一个值填充我的集合,但是当我在其他类中请求它时,我无法获得该值。
这是我的代码:
foreach ($_SESSION['order'] as $row) {
$invoice->setInvoiceBeginDate($row['beginDatum']);
$invoice->setInvoiceEndDate($row['eindDatum']);
$invoice->setDeliveryLocation($row['locatie']);
$invoice->insertInvoice();
$invoice->setLastInsertedInvoice_ID($invoice->sqlSelect("invoice_ID", "invoice", "", "","","1")->fetch(PDO::FETCH_COLUMN));
$invoice->setCarId($row['car']);
//here is where the error is coming from
if ($order->insertOrder()) {
$status = 1;
} else {
$status = 0;
$invoice->deleteInvoice();
}
}
和我的2个班级:
class Invoice extends DynamicSql
{
private $invoiceBeginDate;
private $invoiceEndDate;
private $deliveryLocation;
private $invoiceId;
private $lastInsertedId;
private $carId;
public function insertInvoice()
{
if ($this->sqlInsert(
"invoice",
array(
"invoiceBeginDate" => $this->getInvoiceBeginDate(),
"invoiceEndDate" => $this->getInvoiceEndDate(),
"deliveryLocation" => $this->getDeliveryLocation()
)
)) {
return true;
} else {
return false;
}
}
public function deleteInvoice()
{
if($this->sqlDelete(
"invoice",
array(
["invoice_ID" => $this->getLastInsertedInvoice_ID()]
)
))
{
return true;
}
else
{
return false;
}
}
public function setInvoiceBeginDate($value){
$this->invoiceBeginDate = $value;
}
public function getInvoiceBeginDate(){
return $this->invoiceBeginDate;
}
public function setInvoiceEndDate($value){
$this->invoiceEndDate = $value;
}
public function getInvoiceEndDate(){
return $this->invoiceEndDate;
}
public function setDeliveryLocation($value){
$this->deliveryLocation = $value;
}
public function getDeliveryLocation(){
return $this->deliveryLocation;
}
public function setInvoiceId($value){
$this->invoiceId = $value;
}
public function getInvoiceId(){
return $this->invoiceId;
}
public function setLastInsertedInvoice_ID($value){
$this->lastInsertedId = $value;
}
public function getLastInsertedInvoice_ID(){
return $this->lastInsertedId;
}
public function setCarId($value){
$this->carId = $value;
}
public function getCarId(){
return $this->carId;
}
}
class Order扩展Invoice {
public function insertOrder(){
echo $this->getLastInsertedInvoice_ID(), $_SESSION['user_session'], $this->getCarId();
$this->sqlInsert("orders",
array(
"invoiceId" => $this->getLastInsertedInvoice_ID(),
"user_ID" => $_SESSION['user_session'],
"carId" => $this->getCarId()
)
);
}
}
这是我的错误,invoiceId为空:
27(27来自$ _SESSION [' user_session']其他2未设置 由于某种原因)致命错误:未捕获的异常' PDOException'同 消息' SQLSTATE [23000]:完整性约束违规:1048列 ' invoiceId'不能为空'在 C:\ xampp \ htdocs \ TestExame \ includes \ sqlQuerry.php:177堆栈跟踪:#0 C:\ XAMPP \ htdocs中\ TestExame \包括\ sqlQuerry.php(177): PDOStatement-> execute()#1 C:\ XAMPP \ htdocs中\ TestExame \包括\ sqlQuerry.php(662): DynamicSql-> sqlInsert(' orders',Array)#2 C:\ xampp \ htdocs \ TestExame \ cart.php(54):Order-> insertOrder()#3 {main} 在第177行的C:\ xampp \ htdocs \ TestExame \ includes \ sqlQuerry.php中抛出
我希望有人可以帮助我。