【发布时间】:2019-04-09 20:58:51
【问题描述】:
我不断收到此错误(检查问题底部的确切错误)我一次又一次地检查,但找不到问题所在。似乎没事。在 insert_batch 上它工作正常,但在 update_batch 上我收到此错误。这是我当前的代码
Codeigniter 模型: 这是正确获取数据的模型
function get_seeds($tournament_id) {
$this->db->where('tournament_id', $tournament_id);
$result = $this->db->get('tournament_seed');
return $result->result();
}
Codeigniter 控制器: 这是我的控制器,我在其中检查是否有种子行。如果是,则更新,否则插入。
$check_seeds = (object)$this->tournament_model->get_seeds($tournament_id);
if ($_POST) {
foreach ($check_seeds as $key => $value) {
if(!empty($key) && !empty($value)) {
$seeded[] = array(
'id' => $value->id,
'tournament_id' => $tournament_id,
'stage_id' => $stage_id,
'seed_id' => $value,
'team_name' => $key,
);
$this->db->update_batch('tournament_seed', $seeded, 'id');
redirect('organizer/tournaments);
} else {
//something
}
}
}
Print_r($check_seeds)
stdClass Object
(
[0] => stdClass Object
(
[id] => 3
[tournament_id] => 713161746
[stage_id] => 3
[seed_id] => 1
[team_name] => -V-ATTAX
)
[1] => stdClass Object
(
[id] => 4
[tournament_id] => 713161746
[stage_id] => 3
[seed_id] => 2
[team_name] => NIP
)
[2] => stdClass Object
(
[id] => 5
[tournament_id] => 713161746
[stage_id] => 3
[seed_id] => 3
[team_name] => fnatic
)
)
错误
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: database/DB_query_builder.php
Line Number: 1970
Backtrace:
File: E:\xampp\htdocs\hltv\application\controllers\organizer\Tournaments.php
Line: 1065
Function: update_batch
File: E:\xampp\htdocs\hltv\index.php
Line: 315
Function: require_once
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ELSE `seed_id` END, `team_name` = CASE WHEN `id` = '4' THEN '1' ELSE `team_name' at line 7
UPDATE `tournament_seed` SET `tournament_id` = CASE WHEN `id` = '4' THEN '713161746' ELSE `tournament_id` END, `stage_id` = CASE WHEN `id` = '4' THEN '3' ELSE `stage_id` END, `seed_id` = CASE WHEN `id` = '4' THEN ELSE `seed_id` END, `team_name` = CASE WHEN `id` = '4' THEN '1' ELSE `team_name` END WHERE `id` IN('4')
Filename: E:/xampp/htdocs/hltv/system/database/DB_driver.php
Line Number: 691
【问题讨论】: