更新时间:2023-01-30 17:18:08
忘了bindParam
,只需使用execute
并将值$array
传递给它即可:
Forget about bindParam
, just use execute
and pass it the values of $array
:
$STH->execute($array);
或者,您可以完全擦除命名的参数,以简化您的代码:
Alternatively, you could scratch the named parameters altogether to simplify your code a little:
$columnString = implode(',', array_keys($array));
$valueString = implode(',', array_fill(0, count($array), '?'));
$STH = $core->dbh->prepare("INSERT INTO table ({$columnString}) VALUES ({$valueString})");
$STH->execute(array_values($array));