我需要根据我的选择使行名称动态化。如何使用bind_param让我使用以下代码?
更新:我的动态行名称不起作用的主要问题。它给了我一个错误 -
PHP Fatal error: Call to a member function execute() on a non-object
代码
$myitem = 'something2';
$result = getResult($myitem);
function getResult($myitem) {
global $DBconnection;
$rowName = $myitem;
$stmt = $mysqli->prepare("SELECT
id,
something1,
something2,
something3
FROM table
WHERE ? = ? // ERROR
");
$stmt->bind_param("ss", $rowName, $myitem); // ERROR
$stmt->execute();
$stmt->bind_result($id, $something1, $something2, $something3);
while ($stmt->fetch()){
$row[] = array('id' => $id, 'something1' => $something1, 'something2' => $something2, 'something3' => $something3);
}
$stmt->close();
if (isset($row)) {
return ($row);
}
}
谢谢。