首页| 新闻| 娱乐| 游戏| 科普| 文学| 编程| 系统| 数据库| 建站| 学院| 产品| 网管| 维修| 办公| 热点
今天在讲解Thinkphp框架的时候在使用ThinkPHP基础模型类提供的addAll()方法进行多条数据写入时报错了,而且使用模型的getError()都获取不到错误提示!没错,获取不到错误!所以我认为这是ThinkPHP框架设计中存在的Bug。在学生都去吃饭时我自己翻看了框架底层对于addAll()的实现。我的课堂代码是这样写的:if (M('SubOrder')->addAll($allGoods) === false) { $this->rollback(); throw new Exception('提交订单失败,请稍后再试!', 0);}因为为了获取数据方便我的$allGoods是使用goods_id来索引的,错误就出在这儿但是让我恨不能理解,让我们一一道来。我的$allGoods的结构是这样的array(2) { [5] => array(4) { ["goods_id"] => string(1) "5" ["PRice"] => string(6) "123.00" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" } [15] => array(4) { ["goods_id"] => string(2) "15" ["price"] => string(4) "0.10" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" }}查看其它都没有问题的情况下唯一可能出错的就是数据的索引方式了,难道TP只能使用从0开始索引的二维数组?这让我很不能理解,作为一个框架应该考虑到通用性,所以翻看了TP中MySQL驱动里关于insertAll()的实现,因为model中的addAll()就是调用驱动里的insertAll()实现的:$result = $this->db->insertAll($dataList,$options,$replace);所以就是这样了!public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
我的课堂代码是这样写的:
if (M('SubOrder')->addAll($allGoods) === false) { $this->rollback(); throw new Exception('提交订单失败,请稍后再试!', 0);}因为为了获取数据方便我的$allGoods是使用goods_id来索引的,错误就出在这儿但是让我恨不能理解,让我们一一道来。我的$allGoods的结构是这样的array(2) { [5] => array(4) { ["goods_id"] => string(1) "5" ["PRice"] => string(6) "123.00" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" } [15] => array(4) { ["goods_id"] => string(2) "15" ["price"] => string(4) "0.10" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" }}查看其它都没有问题的情况下唯一可能出错的就是数据的索引方式了,难道TP只能使用从0开始索引的二维数组?这让我很不能理解,作为一个框架应该考虑到通用性,所以翻看了TP中MySQL驱动里关于insertAll()的实现,因为model中的addAll()就是调用驱动里的insertAll()实现的:$result = $this->db->insertAll($dataList,$options,$replace);所以就是这样了!public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
if (M('SubOrder')->addAll($allGoods) === false) {
$this->rollback();
throw new Exception('提交订单失败,请稍后再试!', 0);
}因为为了获取数据方便我的$allGoods是使用goods_id来索引的,错误就出在这儿但是让我恨不能理解,让我们一一道来。我的$allGoods的结构是这样的array(2) { [5] => array(4) { ["goods_id"] => string(1) "5" ["PRice"] => string(6) "123.00" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" } [15] => array(4) { ["goods_id"] => string(2) "15" ["price"] => string(4) "0.10" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" }}查看其它都没有问题的情况下唯一可能出错的就是数据的索引方式了,难道TP只能使用从0开始索引的二维数组?这让我很不能理解,作为一个框架应该考虑到通用性,所以翻看了TP中MySQL驱动里关于insertAll()的实现,因为model中的addAll()就是调用驱动里的insertAll()实现的:$result = $this->db->insertAll($dataList,$options,$replace);所以就是这样了!public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
因为为了获取数据方便我的$allGoods是使用goods_id来索引的,错误就出在这儿但是让我恨不能理解,让我们一一道来。
我的$allGoods的结构是这样的
array(2) { [5] => array(4) { ["goods_id"] => string(1) "5" ["PRice"] => string(6) "123.00" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" } [15] => array(4) { ["goods_id"] => string(2) "15" ["price"] => string(4) "0.10" ["goods_num"] => string(1) "2" ["order_id"] => string(2) "16" }}查看其它都没有问题的情况下唯一可能出错的就是数据的索引方式了,难道TP只能使用从0开始索引的二维数组?这让我很不能理解,作为一个框架应该考虑到通用性,所以翻看了TP中MySQL驱动里关于insertAll()的实现,因为model中的addAll()就是调用驱动里的insertAll()实现的:$result = $this->db->insertAll($dataList,$options,$replace);所以就是这样了!public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
查看其它都没有问题的情况下唯一可能出错的就是数据的索引方式了,难道TP只能使用从0开始索引的二维数组?这让我很不能理解,作为一个框架应该考虑到通用性,所以翻看了TP中MySQL驱动里关于insertAll()的实现,因为model中的addAll()就是调用驱动里的insertAll()实现的:
$result = $this->db->insertAll($dataList,$options,$replace);所以就是这样了!public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
所以就是这样了!
public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
public function insertAll($dataSet,$options=array(),$replace=false) {
$values = array();
$this->model = $options['model'];
if(!is_array($dataSet[0])) return false; //问题就出在这儿问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
问题就出在对于$dataSet[0]的判断中!顿时心中千军万马奔腾而过,作为框架如果非要这样操作为什么不先对$dataSet重写索引后来处理呢?好吧,我要改,我要改框架!-_-
框架修改方式。打开Library/Think/Db/Driver/Mysql.class.php找到insertAll方法修改如下
public function insertAll($dataSet,$options=array(),$replace=false) { $values = array(); $this->model = $options['model']; $firstRow = array_shift($dataSet); //取出传入数组的第一条数据 if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断 $dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
$firstRow = array_shift($dataSet); //取出传入数组的第一条数据
if(!is_array($firstRow)) return false; //根据框架的思想进行简单的数组判断
$dataSet[] = $firstRow; //重新赋值到待写入数组的元素中至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
至此,问题解决。最后,ThinkPHP官方已经致力于开发ThinkPHP5了,ThinkPHP3.2.3的维护生命周期已经结束了,所以还在使用ThinkPHP3.2.3作为开发框架的公司只能靠自己了。
索泰发布一款GTX 1070 Mini迷
AMD新旗舰显卡轻松干翻NVIDIA
索泰发布一款GTX 1070 Mini迷你版本:小机
芭蕾舞蹈表演,真实美到极致
下午茶时间,悠然自得的休憩
充斥这繁华奢靡气息的城市迪拜风景图片
从山间到田野再到大海美丽的自然风景图片
肉食主义者的最爱美食烤肉图片
夏日甜心草莓美食图片
人逢知己千杯少,喝酒搞笑图集
搞笑试卷,学生恶搞答题
新闻热点
疑难解答
图片精选
网站加速 PHP 缓冲的免费实现方法
网友关注