PDO

suggest change

Versions

The original version list on this page was PHP 5.0 through 7.1. PDO has shipped with PHP since 5.1.

Introduction

The PDO (PHP Data Objects) extension allows developers to connect to numerous different types of databases and execute queries against them in a uniform, object-oriented manner.

Syntax

Remarks

Warning Do not forget to check for exceptions while using lastInsertId(). PDO throws only when the error mode is PDO::ERRMODE_EXCEPTION, which has been the default since PHP 8.0. The driver can raise:

SQLSTATE IM001 : Driver does not support this function

Check for that exception like this:

// Retrieving the last inserted id
$id = null;

try {
    $id = $pdo->lastInsertId(); // return value is a string
}
catch( PDOException $e ) {
    echo $e->getMessage();
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents