Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
好的,很明显我现在的代码不起作用
$stmt = $pdo->prepare('SELECT * FROM '.$table.' WHERE id = :p'); foreach($stmt->execute(array(':p' => $_GET['p'])) as $row) { echo $row['id']; }
但是,希望你能理解我想要做什么。我想从与 id 相关的 sql 条目返回值。我不确定我需要使用什么组合的准备、执行或查询来实现这一点。
谢谢
最简单的答案:
$stmt = $pdo->prepare('SELECT * FROM ' . $table . ' WHERE id = :p'); $stmt->execute(array(':p' => $_GET['p'])); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['id']; }
我强烈建议看一下这些单独的方法的作用:
http://php.net/manual/en/book.pdo.php