编辑:这已解决。这是一个查询错误模式名称的简单案例。其余代码有效(即使它不是很好的编码实践)。
在这里问了同样的问题:
不过,我在该线程上没有看到可靠的解决方案。基本上我的问题是它说删除成功,但没有删除任何内容。我很确定它与删除语句中的 $1 有关,但我不知道还能尝试什么。有人可以向我解释为什么这不起作用吗?这是我的代码:
$mySearch = $_POST['row'];
if($_POST['tbl'] == "country"){
$query = 'DELETE FROM lab2.country WHERE country.country_code = $1';
}
elseif($_POST['tbl'] == "city"){
$query = 'DELETE FROM lab2.city WHERE city.id = $1';
}
elseif($_POST['tbl'] == "language"){
$query = 'DELETE FROM lab2.country_language WHERE country_language.country_code = $1';
}
$stmt = pg_prepare($conn, $mySearch, $query); //prepare statement
$result = pg_execute($conn, $mySearch, array($mySearch)); //execute
if(!$result){ //error if no value in $result
die("Unable to execute: " . pg_last_error($conn));
} else{
//results are good so output them to HTML
echo "Delete was successful <br />";
echo "Return to <a href=\"" . $_SERVER['HTTP_REFERER'] . "\">search page</a>";
}
pg_free_result($result);
pg_close($conn);
return;