SoFunction
Updated on 2025-04-13

Pear DB beginner guide tutorial

<?php
/*
* From the DB_(driver) objects
*/
// get the object with, ie:
$db DB::connect('mysql://user:pass@localhost/my_db');
 
// Set options
$db->setErrorHandling();
$db->setFetchmode();
// Information
$db->affectedRows();
$db->tableInfo();
// Database manipulation
$db->query();
// Data fetch
$db->nextId();
$db->getOne();
$db->getRow();
$db->getCol();
$db->getAssoc();
$db->getAll();
// Place holders and execute related
$db->quote();
$db->prepare();
$db->execute();
$db->executeMultiple();
// Transactions
$db->autoCommit();
$db->commit();
$db->rollback();
// Disconnection
$db->disconnect();
 
/*
* From DB_result objects
*/
// get the object with, ie:
$res $db->query('select * from foo');
 
// Data fetch
$res->fetchRow();
$res->fetchInto();
// Result Info
$res->numCols();
$res->numRows();
$res->tableInfo();
// Free
$res->free();
 
/*
* From DB_error objects
*/
// get the object with, ie:
$error $db->query('select * from no_table');
 
$error->getMessage();
$error->getDebugInfo();
$error->toString();
?>