【发布时间】:2016-08-17 18:17:03
【问题描述】:
你好,我正在尝试运行一个名为“sp_tbl_prototype_edit”的mysql存储过程
这个存储过程有两个参数:
p_Techname (VARCHAR(10))
p_Value (INT)
看起来下面的 PHP 函数没有按我的意愿保存(编辑数据库中的值)值。
function edit_record($title, $value){
// Prepares IN parameters
$mysqli->query("SET p_Techname = '" . $title . "'");
$mysqli->query("SET p_Value = '" . $value ."'");
// Call stored procedure
if(!$mysqli->query("CALL sp_tbl_prototype_edit (@p_Techname, @p_Value)"))
{
if($mysqli) $mysqli->close(); // Close DB connection
//header('Location: error.php?error=QueryFailure');
die();
}
if($mysqli) $mysqli->close(); // Close DB connection
}
请问您有什么解决此问题的建议吗?提前非常感谢。
【问题讨论】:
-
如果查询失败,您只需重定向。您应该让系统告诉您失败的原因,例如
die($mysqli->error);。请注意,您很容易受到 sql injection attacks 的攻击 -
为什么不直接传参数
$mysqli->query("CALL sp_tbl_prototype_edit ($title, $value)")?我认为您的临时变量不会在查询之间持续存在。如果可行,那么您应该参数化它们 - 尤其是如果$input和$value是用户提交的数据。
标签: php mysql stored-procedures