Справочник по PDO

 
Подключение к БД:
try {  
  # MS SQL Server и Sybase через PDO_DBLIB  
  $DBH = new PDO("mssql:host=$host;dbname=$dbname", $user, $pass);  
  $DBH = new PDO("sybase:host=$host;dbname=$dbname", $user, $pass);  
  
  # MySQL через PDO_MYSQL  
  $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);  
  
  # SQLite  
  $DBH = new PDO("sqlite:my/database/path/database.db");  
}  
catch(PDOException $e) {  
    echo $e->getMessage();  
}
 
Использование placeholder'ов:
# данные, которые мы вставляем  
$data = array( 'name' => 'Cathy', 'addr' => '9 Dark and Twisty', 'city' => 'Cardiff' );  
$STH = $DBH->prepare("INSERT INTO folks (name, addr, city) values (:name, :addr, :city)");  
$STH->execute($data);


Простой запрос к базе (получение имент таблиц, содержащихся в базе SQLite3):
$STH = $DBH->query("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE '%_hex';");
$tbls = $STH->fetchAll(PDO::FETCH_COLUMN, 0);

Описание класса выборки данных (класс объекта $STH):

/* Свойства */
readonly string $queryString;

/* Методы */
public bool bindColumn ( mixed $column , mixed &$param [, int $type [, int $maxlen [, mixed $driverdata ]]] )
public bool bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )
public bool bindValue ( mixed $parameter , mixed $value [, int $data_type = PDO::PARAM_STR ] )
public bool closeCursor ( void )
public int columnCount ( void )
public void debugDumpParams ( void )
public string errorCode ( void )
public array errorInfo ( void )
public bool execute ([ array $input_parameters ] )
public mixed fetch ([ int $fetch_style [, int $cursor_orientation = PDO::FETCH_ORI_NEXT [, int $cursor_offset = 0 ]]] )
public array fetchAll ([ int $fetch_style [, mixed $fetch_argument [, array $ctor_args = array() ]]] )
public mixed fetchColumn ([ int $column_number = 0 ] )
public mixed fetchObject ([ string $class_name = "stdClass" [, array $ctor_args ]] )
public mixed getAttribute ( int $attribute )
public array getColumnMeta ( int $column )
public bool nextRowset ( void )
public int rowCount ( void )
public bool setAttribute ( int $attribute , mixed $value )
public bool setFetchMode ( int $mode )