Php 错误:添加到购物车时调用未定义的函数lastInsertId()
我试图将数量和大小的值插入数据库,但出现错误: 使用通过ajax提交并解析为的“添加到购物车”按钮时,调用未定义函数Php 错误:添加到购物车时调用未定义的函数lastInsertId(),php,Php,我试图将数量和大小的值插入数据库,但出现错误: 使用通过ajax提交并解析为的“添加到购物车”按钮时,调用未定义函数lastInsertId() add-cart.php 我正在学习mysqli教程,但是我正在使用PDO,我找不到解决这个问题的方法 我正在将购物车添加到数据库中: $items_json = json_encode($new_items); $cart_expire = date("Y-m-d H:i:s", strtotime("+30 days")); $some
lastInsertId()
add-cart.php
我正在学习mysqli教程,但是我正在使用PDO,我找不到解决这个问题的方法
我正在将购物车添加到数据库中:
$items_json = json_encode($new_items);
$cart_expire = date("Y-m-d H:i:s", strtotime("+30 days"));
$something=$veza->prepare("UPDATE cart SET items = '$items_json',expire_date= '$cart_expire'WHERE id ='$cart_id'");
$something ->execute();
setcookie(CART_COOKIE,'',1,'/',$domain,false);
setcookie(CART_COOKIE,$cart_id,CART_COOKIE_EXPIRE,'/',$domain,false);
}else {
//add cart inside database
$items_json = json_encode($item);
$cart_expire = date("Y-m-d H:i:s",strtotime("+30 days"));
$smth=$veza->prepare("INSERT INTO cart (items,expire_date) VALUES ('$items_json','$cart_expire')");
$smth->execute();
$cart_id = $smth>lastInsertId();
setcookie(CART_COOKIE,$cart_id,CART_COOKIE_EXPIRE,'/',$domain,false);
}
lastinertid
不属于PDOStatement
类,而是属于PDO
实例
$cart_id = $veza->lastInsertId();
看那行……我在看,还是什么都没有……它缺少一个
-
。。