Fatal error: Non-static method in PHP using PDO for MySQL
<p>I'm inserting, using PDO, a row into the table, and I need the id of the new row so I can redirect to the new page based off that row.</p>

<p>When I use</p>

<p><code>$id = PDO::lastInsertId();</code></p>

<p>I get </p>

<pre><code>Fatal error: Non-static method PDO::lastInsertId() cannot be called statically in C:\xampp\htdocs\createimage.php on line 16
</code></pre>

<p>Here's the php that results in an error:</p>

<pre><code>&lt;?php 

$title = $_POST['title'];
$caption = $_POST['caption'];

$conn = new PDO('mysql:host=localhost;dbname=imagesite', 'root', '');

$stmt = $conn-&gt;prepare('INSERT INTO images (id,link,title,caption) VALUES (NULL,:link,:title,:caption)');

$stmt-&gt;execute(array(
    'link' =&gt; 'fake',
    'title' =&gt; $title,
    'caption' =&gt; $caption
    ));

$id = PDO::lastInsertId();

header("Location: localhost/image?id=$id");
</code></pre>

<p>Can anyone tell what's going wrong? Or another way to achieve that I'm looking to do?</p>
