0
$stmt = $connection->prepare("SELECT id FROM articles WHERE position =? LIMIT 1");
$stmt-> bind_param('i',$call );
$stmt->execute();
$result = $stmt->fetch();
$oldpostid = $result;
$stmt->close(); 

I don't see anything wrong with it, but it is returning 1 or nothing. $call is set and integer. I tried this too:

$stmt = $connection->prepare("SELECT * FROM articles WHERE position =? LIMIT 1");
$oldpostid = $result['id'];
4

2 回答 2

3

假设这一切正常,您还需要绑定结果变量。 mysqli_stmt_fetch返回一个布尔值:

$stmt->execute();
$stmt->bind_result($id);
$stmt->fetch();
$oldpostid = $id;
于 2013-07-18T21:05:57.817 回答
1

您似乎在混合 mysqli 和 PDO。第一行是PDO

$stmt = $connection->prepare("SELECT id FROM articles WHERE position =? LIMIT 1");

下一行是mysqli

$stmt-> bind_param('i',$call );

应该是 PDO 占位符手册示例 4中的未命名变量

$stmt-> bindParam(1,$call );
$stmt->execute(); 

使用数组

$stmt->execute(array($call));
于 2013-07-18T22:05:06.130 回答