致命错误:未捕获的错误:在bool上调用成员函数bindParam()

问题描述 投票:-2回答:1

我尝试在FormulaireModel.php中运行此功能,我遇到了此错误,我使用MVC PHP。预先感谢您的回答

public function getUnic( $id ){
    try{
        if($q = $this->_db->prepare('SELECT * FROM `imp_operations_fact` WHERE `ID`=:id')!=false){
            if($q->bindParam(':id', $id) && $q->execute()){
                $result = $q->fecth(PDO::FETCH_ASSOC);
            }return $result;
        }return false;
    }catch (PDOException $e){
        die($e->getMessage());
    }
}

致命错误:未捕获的错误:调用成员函数bindParam()布尔在C:\ xampp \ htdocs \ ORP_PHP \ App \ Models \ FormulaireModel.php:40堆栈跟踪:#0C:\ xampp \ htdocs \ ORP_PHP \ App \ Controllers \ FormulaireController.php(78):FormulaireModel-> getUnic('18')#1C:\ xampp \ htdocs \ ORP_PHP \ FW \ core \ CoreController.php(153):FormulaireController-> editerAction()#2C:\ xampp \ htdocs \ ORP_PHP \ index.php(34):CoreController-> launcher('editerAction')#3 {main}被抛出C:\ xampp \ htdocs \ ORP_PHP \ App \ Models \ FormulaireModel.php,第40行

php pdo
1个回答
-2
投票
    try{
        if($q = $this->_db->prepare('SELECT * FROM `imp_operations_fact` WHERE `ID`=:id')){
            if($q->bindParam(':id', $id) && $q->execute()){
                $result = $q->fetch(PDO::FETCH_ASSOC);
            }return $result;
        }return false;
    }catch (PDOException $e){
        die($e->getMessage());
    }
}

随后检查函数是否返回true或false。

© www.soinside.com 2019 - 2024. All rights reserved.