首页 > 解决方案 > 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 " 

标签: phppdo

解决方案


推荐阅读