PHP 面向对象的插入不工作

PHP object orientated insert not working

我正在尝试将订单详细信息插入 mysql 数据库,但是它不起作用。下面是 class 和函数

class Order extends Database {
    public function insertOrderRef($sessid, $sessionmember, $total) {
        $sql = "INSERT INTO `orders` (order-id, total, member-id, complete) VALUES (:sessid,:total,:sessionmember, '0')";
        $q = $this->conn->prepare($sql);
        $q->execute(array(':sessid'=>$sessid,':total'=>$total,':sessionmember'=>$sessionmember));
    }
}

这里是函数调用

$createorder = new Order;
$createorder->insertOrderRef($sessid, $sessionmember, $total);

我哪里错了?

当您的列名使用连字符时,您需要将它们用反引号括起来。

$sql = "INSERT INTO `orders` (`order-id`, `total`, `member-id`, `complete`) VALUES (:sessid,:total,:sessionmember, '0')";