【发布时间】:2020-09-05 02:42:11
【问题描述】:
我正在使用 foreach 循环插入多个表,并且我想要唯一键列名,因为它在运行时违反了唯一键约束,因此我可以修改值并插入它。
foreach ($data as $table_name){
$sql="INSERT INTO $table_name ($column_name) VALUES ($column_vlues)"
$result=query_params($db_conn,$sql,$params)
if($result){
//Do nothing. Its fine
}else{
//If its voileting the unique key contraints then change the column value like new column value = $column_name_which_voileting.$value and then insert it.
}
}
如有任何帮助,将不胜感激。
【问题讨论】:
-
它为您提供约束的名称,您可以从中推断出列名。您使用的是什么语言和 API?
-
PHP,Postgresql @LaurenzAlbe
标签: php sql postgresql