好的,所以我有一个看起来像的 php 数组
array('somehash' => 'someotherhash', 'somehash2' => 'someotherhash2');
这里 somehash = producthash 和 someotherhash = tohash
$db->query('UPDATE sometable SET status = '.self::STATUS_NOT_AVAILABLE.', towhere = '.self::TO_WHERE.', '.
.'tohash = WHEN or IF or ??? and how ?, '.
.'WHERE status = '.self::STATUS_AVAILABLE.' AND '.
.'producthash IN (' . implode(',' , $prodarray) . ')') or $db->err(__FILE__,__LINE__);
所以在上面的查询中,我希望通过mysql 字段tohash
从 php 数组中获取值producthash
就像是tohash = IF(producthash IN '.$prodarray.', $prodarray['producthash'] , whatever)
当然,上述 IF 不起作用,因为我没有 producthash 值$prodarray['producthash']
任何人都知道解决这个问题的方法,因为我在数组中有超过 1000 个值并且不想运行数千个更新
在这种情况下,INSERT INTO ON DUPLICATE KEY 是不可能的,因为此表唯一键基于 3 个字段,并且在执行此更新时我没有所有三个字段值。