类的可捕获的致命错误 - PHP

时间:2011-02-02 00:24:32

标签: php oop class

获取此错误...(MySQLiPluggin是我的数据库类名称)

  

捕获致命错误:MySQLiPluggin类的对象无法转换为字符串

我有一个php表单,它发布数据,并尝试添加到数据库。

if(isset($_POST["submit"])){    

    $formNewTreatment->setStickyData($_POST);
    $formNewTreatment->checkNotEmpty("treatName");
    $formNewTreatment->checkNotEmpty("treatPrice");
    $formNewTreatment->checkNotEmpty("treatBlurb");

    if ($form->valid){

        $addTreatment = new Treatment();

        $addTreatment->setTreatName($_POST["treatName"]);
        $addTreatment->setTreatPrice($_POST["treatPrice"]);
        $addTreatment->setTreatBlurb($_POST["treatBlurb"]);
        $addTreatment->setSubID($_POST["treatCategory"]);
        $addTreatment->addTreatments();

            $sAdminMessage = "saved SMILEYFACE";    

        }else{

            $sAdminMessage = "not saved SADFACE";

        }

}

当我点击提交时,我收到上述错误。

这是我的$ addTreatment:

    public function addTreatments(){
        global $database;

        if($this->bExisting == false){

            $sQuery = "INSERT INTO treatments (`treatmentName`, `treatmentPrice`, `treatmentBlurb`, `subID`) 
            VALUES ('".$database->escape_value($this->sName)."', '".$database->escape_value($this->sPrice)."', '".$database->escape_value($this->sBlurb)."', '".$database->escape_value($this->iSubID)."')";

            $resultAddTreatment = $database->query($sQuery);

            if($resultAddTreatment){

                $this->$iTreatmentID = $this->$database->get_last_insert_id();

                $this->bExsisting = true;

            }else{

                    die("save has failed, you've done something wrong.");

            }

        }

    }

感谢。 :)

1 个答案:

答案 0 :(得分:1)

好吧,不确定是不是导致问题的bug,但这对我来说似乎是个错误:

$this->$database->get_last_insert_id();

应该是:

$database->get_last_insert_id();