我正在使用PDO插入表中的一行,我需要新行的id,以便我可以根据该行重定向到新页面.
我用的时候
$id = PDO :: lastInsertId();
我明白了
Fatal error: Non-static method PDO::lastInsertId() cannot be called statically in C:\xampp\htdocs\createimage.PHP on line 16
<?PHP $title = $_POST['title']; $caption = $_POST['caption']; $conn = new PDO('MysqL:host=localhost;dbname=imagesite','root',''); $stmt = $conn->prepare('INSERT INTO images (id,link,title,caption) VALUES (NULL,:link,:title,:caption)'); $stmt->execute(array( 'link' => 'fake','title' => $title,'caption' => $caption )); $id = PDO::lastInsertId(); header("Location: localhost/image?id=$id");
有谁能说出出了什么问题?或者另一种实现我想做的方式?