无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了php+pdo实现的购物车类。分享给大家供大家参考,具体如下:
<"mysql:host=$host;dbname=$db", "$user", "$pwd", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $this->pdo->query("set names utf8"); } catch (PDOException $e) { echo $e->getMessage(); } } //添加商品到购物车 public function add_cart($productid, $num) { $sql = "select price from shop_product where id="; $stmt = $this->pdo->prepare($sql); $stmt->execute(array($productid)); $data = $stmt->fetch(PDO::FETCH_ASSOC); $price = $data['price']; $createtime = time(); $sql = "select * from shop_cart where productid="; $stmt = $this->pdo->prepare($sql); $stmt->execute(array($productid, $_SESSION['user_id'])); $data = $stmt->fetch(PDO::FETCH_ASSOC); if ($data) { $sql = "update shop_cart set num=num+"; $params = array($num, $_SESSION['user_id'], $productid); } else { $sql = "insert into shop_cart(productid,num,userid,price,createtime) values("; $params = array($productid, $num, $_SESSION['user_id'], $price, $createtime); } $stmt = $this->pdo->prepare($sql); $stmt->execute($params); $rows = $stmt->rowCount(); return $rows "update shop_cart set num="; $stmt = $this->pdo->prepare($sql); $stmt->execute(array($num, $_SESSION['user_id'], $productid)); $rows = $stmt->rowCount(); return $rows "delete from shop_cart where userid="; $stmt = $this->pdo->prepare($sql); $this->pdo->execute(array($this->user_id)); $rows = $stmt->rowCount(); return $rows "delete from shop_cart where productid="; $stmt = $this->pdo->prepare($sql); $stmt->execute(array($productid, $_SESSION['user_id'])); $rows = $stmt->rowCount(); return $rows "_blank" href="//www.jb51.net/Special/554.htm">PHP+MySQL购物车开发专题》、《php面向对象程序设计入门教程》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总》希望本文所述对大家PHP程序设计有所帮助。
标签:
php,pdo,购物车类
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】
- 刘宇.2024-宇宙诗人【哔哟哔哟文化】【FLAC分轨】
- 《全景声白噪音》沉浸式大自然助眠 带你听自然的声音[mp3]
- 纯音入心系列纯音乐《古筝精选 十指弹一赏心曲一心奏出世人心》1CD[MP3][582MB]
- 纯音入心系列纯音乐《古筝与现代音乐的交织》1CD[MP3][96MB]
- 王俪婷.2011-ROMANCE【华研国际】【WAV+CUE】
- 狮子合唱团.2016-LION(引进版)【华纳】【WAV+CUE】
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]