所以价格从数据库中获得两倍,每当我尝试执行这段代码或转换它时,我得到:
捕获致命错误:PDOStatement类的对象无法转换为字符串
try{
$conn = new PDO('mysql:host=localhost;dbname=janes_catering', $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$price = $conn->query("SELECT cost FROM foods WHERE description =
':choice' AND size = ':oice'");
$stmt = $conn->prepare("INSERT foods(description, size, cost)
VALUES ( :choice, :oice, :price)");
$TPrice = (string)$price;
$stmt->bindParam(':choice', $choice, PDO::PARAM_STR);
$stmt->bindParam(':TPrice', $TPrice, PDO::PARAM_STR);
$stmt->bindParam(':oice', $oice, PDO::PARAM_STR);
$stmt->execute();
}