准备好的声明Param工作一次

时间:2017-02-27 12:07:00

标签: mysqli prepared-statement

您好,

我正在开展一个小项目,我喜欢Query来为我检查一些东西。但是,为此我需要选择WHERE子句中也需要的东西。

// Prepare Query
$sql = "SELECT ? FROM permissions WHERE (req = ? AND single_delete = '1')";
$stmt = $db->prepare($sql);

// Bind Parameters and execute.
$stmt->bind_param("si", $action, $user['permissions']);
$stmt->execute();

// Store result and make it a variable.
$stmt->store_result();
$permissioncount = $stmt->num_rows;

return $permissioncount;

像这样它正在发挥作用。它返回正确的计数。但是,只要我将single_delete更改为变量$action,它就会返回0。变量$action包含single_delete。我的问题是,为什么不可能或我做错了什么?

代码

    // Prepare Query
$sql = "SELECT ? FROM permissions WHERE (req = ? AND ? = '1')";
$stmt = $db->prepare($sql);

// Bind Parameters and execute.
$stmt->bind_param("sis", $action, $user['permissions'], $action);
$stmt->execute();

// Store result and make it a variable.
$stmt->store_result();
$permissioncount = $stmt->num_rows;

return $permissioncount;

0 个答案:

没有答案