Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获得;无效参数编号:未绑定任何参数";来自PDO_Php_Pdo - Fatal编程技术网

Php 获得;无效参数编号:未绑定任何参数";来自PDO

Php 获得;无效参数编号:未绑定任何参数";来自PDO,php,pdo,Php,Pdo,我的代码报告此错误: 参数编号无效:第6行语句->执行()上未绑定任何参数 代码 评论帖子 我只想在post中获取id为 至少您使用的是prepared语句,但是在prepare中您有id=:id,因此您需要向execute中传递一个值,以代替:id $statement->execute(['id' => $id]); 您忘记了bindParam() 您是否var\u dump$posts?错误非常明确,没有绑定任何参数。。。您已经在查询中放置了一个:id占位符(SELEC

我的代码报告此错误:

参数编号无效:第6行语句->执行()上未绑定任何参数

代码


评论帖子
我只想在post中获取id为


至少您使用的是prepared语句,但是在prepare中您有
id=:id
,因此您需要向execute中传递一个值,以代替
:id

$statement->execute(['id' => $id]);
您忘记了bindParam()


您是否
var\u dump
$posts
?错误非常明确,没有绑定任何参数。。。您已经在查询中放置了一个
:id
占位符(
SELECT*FROM post,其中id=:id
)但实际上不需要将数据绑定到它。您需要绑定<代码> $ID<代码>或将其传递给<代码>执行< /COD>作为一个数组,因为它需要替换<代码>:ID < /代码>。考虑使用更好的标题来增加回答的机会,尝试将标题更改为这样的内容:“如何选择具有匹配ID的行”并阅读指南为什么这可能会起作用-你应该添加一个解释,让未来的用户理解代码-只有代码的答案不是答案
$statement->execute(['id' => $id]);
require 'db.php';
$id = $_GET['id'];
$sql = 'SELECT * FROM post where id=:id';
$statement = $connection->prepare($sql);

$statement->bindParam(':id', $id, PDO::PARAM_INT);

$statement->execute();