Php 我的get即使在填充时也返回空?
我是这个网站的新手,但我的代码有问题 我是从PHP中的OOP开始的,现在正在努力使用get和set 我正在用一个值填充我的集合,但是当我在其他类中请求它时,我无法获得该值 这是我的密码:Php 我的get即使在填充时也返回空?,php,pdo,Php,Pdo,我是这个网站的新手,但我的代码有问题 我是从PHP中的OOP开始的,现在正在努力使用get和set 我正在用一个值填充我的集合,但是当我在其他类中请求它时,我无法获得该值 这是我的密码: foreach ($_SESSION['order'] as $row) { $invoice->setInvoiceBeginDate($row['beginDatum']); $invoice->setInvoiceEndDate(
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();
}
}
我的两门课:
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 extends 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来自$\u会话['user\u SESSION'],其他2个未设置
由于某些原因)致命错误:未捕获的异常“PDOException”带有
消息“SQLSTATE[23000]:完整性约束冲突:1048列
中的“invoiceId”不能为null
C:\xampp\htdocs\TestExame\includes\sqlQuery.php:177堆栈跟踪:#0
C:\xampp\htdocs\TestExame\includes\sqlQuery.php(177):
PDO语句->执行()#1
C:\xampp\htdocs\TestExame\includes\sqlQuery.php(662):
DynamicSql->sqlInsert('orders',Array)#2
C:\xampp\htdocs\TestExame\cart.php(54):Order->insertOrder()#3{main}
在第177行的C:\xampp\htdocs\TestExame\includes\sqlQuery.php中抛出
我希望有人能帮我。你得到了什么
getLastInsertedInvoice_ID()
?我在调用$order->insertOrder()之前设置的最后一个插入的发票ID。奇怪的是,它没有设置它。我测试了它,invoiceId和carId都有一个值。通过这个“invoiceId”=>$this->getLastInsertedInvoice\u ID()?:“1000”,检查数据库中存储了什么last id
或1000
?然后1000被插入到我的数据库中,这意味着你在$this->getLastInsertedInvoice_id()
中没有得到值getLastInsertedInvoice_id()
?我在调用$order->insertOrder()之前设置的最后一个插入的发票id。奇怪的是,它没有设置它。我测试了它,invoiceId和carId都有一个值。通过这个“invoiceId”=>$this->getLastInsertedInvoice\u ID()?:“1000”,检查数据库中存储了什么last id
或1000
?然后1000被插入到我的数据库中,这意味着您在$this->getLastInsertedInvoice_id()中没有得到值