php - INSERT INTO table SELECT from another table doesn't give id's
问题描述
我试图弄清楚如何将数据从 select 中插入到一个语句中。
$statement = "INSERT INTO $table2 ($fields2) SELECT $fields$table$whereOrderBy";
echo $statement;
return $datas = $this->query($statement, $fields2, false, null); //fields2 is attributes..
INSERT INTO match_players (match_id,team_id,team_player_id,name,squad_number,display_order,status ) SELECT id,team1_id,210,SUEMA,13,23,first_eleven FROM matches WHERE team1_id = 1 AND is_deleted = 0
//it doesnt show 'team1_id' is 1....
警告:PDOStatement::execute() 期望参数 1 是数组,字符串在第 59 行的 /var/opt/lampp/htdocs/testLAB/query/query.php 中给出
$db->insertSelect('all', ['fields2' => ['match_id', 'team_id', 'team_player_id', 'name', 'squad_number', 'display_order', 'status'], 'fields' => ['id', 'team1_id', $team_player_id, $name, $squad_number, $display_order, $default_status], 'conditions' => ['team1_id' => $id, 'is_deleted' => 0]]);
错误代码:
警告:PDOStatement::execute() 期望参数 1 是数组,字符串在第 59 行的 /var/opt/lampp/htdocs/testLAB/query/query.php 中给出
功能:function prepare($statement, $attributes, $one = false, $fetch = null)
59:$res = $req->execute($attributes);
var_dump($属性):
array(6) { [0]=> string(8) "TYRAJYRA" [1]=> string(1) "1" [2]=> string(2) "44" [3]=> string(13) "not_available" [4]=> string(2) "33" [5]=> string(16) "img/default.jpeg" }
INSERT INTO match_players (match_id,team_id,team_player_id,name,squad_number,display_order,status ) SELECT id,team1_id,211,TYRAJYRA,44,33,not_available FROM matches WHERE team1_id = 1 AND is_deleted = 0
string(71) "match_id,team_id,team_player_id,name,squad_number,display_order,status "
解决方案
推荐阅读
- symfony - 无效的标识符值或配置。api平台
- c# - .NET Core Windows 服务与 Autofac
- html - 在浏览器的默认行为中,边距是否包含在元素的整个宽度中?
- javascript - 引导轮播不适用于多张幻灯片
- c - fopen() 是一个目录,必须改变什么?
- ruby-on-rails - 日期为星期一的 Rails
- docker - 在 Docker Golang SDK imagePull 方法中传递本地 docker 镜像
- html - 如何定位多个信息块彼此之间和页面之间的关系
- docker - 通过脚本重命名普罗米修斯中的图例标签?
- javascript - 带有 JS 的 HTML 在某些浏览器中无法正常工作