我正在尝试使用oop将数据添加到我的产品数据库我试图将信息传递给我的产品类并且我一直收到此错误致命错误:在字符串上调用成员函数insert_product()。
<?php
$product = new Product();
$product_name = $_POST['name'];
$product_type = $_POST['type'];
$price = $_POST['price'];
$product->insert_product($product_name,$product_type,$price);
?>
产品类
<?php
class Product
{
public function insert_product($product_name,$product_type,$price)
{
try {
$stmt = Database::getInstance()->getConnection()->prepare("INSERT INTO products($product_name,$product_type,$price)
VALUES(:product_name,:product_type,:price)");
$stmt->bindparam(":product_name", $product_name);
$stmt->bindparam(":product_type", $product_type);
$stmt->bindparam(":price", $price);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>