0% found this document useful (0 votes)
72 views

ADOdb

ADOdb is a database abstraction layer that allows PHP applications to connect to and interact with various database systems like MySQL, PostgreSQL, and SQL Server using a common API. It provides functions for establishing database connections, running queries to select, insert, update and delete data, and moving through result sets. ADOdb also includes utility functions for pagination, exporting data, transactions, and caching query results.

Uploaded by

Sites Procergs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

ADOdb

ADOdb is a database abstraction layer that allows PHP applications to connect to and interact with various database systems like MySQL, PostgreSQL, and SQL Server using a common API. It provides functions for establishing database connections, running queries to select, insert, update and delete data, and moving through result sets. ADOdb also includes utility functions for pagination, exporting data, transactions, and caching query results.

Uploaded by

Sites Procergs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction to

ADOdb
adodb.sourceforge.net

Prepared by: Michael Fatica mike@fatica.net

Database abstraction layer


MySQL database

mysql_connect()

Postgresql
database

pg_connect()
ADODB

Connect()

PHP

Prepared by: Michael Fatica mike@fatica.net

Background
First encountered in Dreamweaver PHP RAD
extension by Interakt Software (PHakt)
Developed multiple sites with it
(metacalendar.com, consultantdirectory.org)
Very stable and fast
Easy to learn, approachable syntax
Makes DB driven Web sites highly portable
Supports caching, automatic results output
Prepared by: Michael Fatica mike@fatica.net

Installation & Database Types


Copy the files to your Web site root e.g.
www.fatica.net/adodb
Supported database drivers:
MySQL, Oracle, Microsoft SQL Server,
Sybase, Sybase SQL Anywhere, Informix,
PostgreSQL, FrontBase, SQLite, Interbase
(Firebird and Borland variants), Foxpro,
Access, ADO, DB2, SAP DB and ODBC.

Prepared by: Michael Fatica mike@fatica.net

Establishing a connection

$dbconn = NewADOConnection(databasedrivername);
$dbconn->Connect(localhost,fatica,password,dbname);
PConnect v.s. Connect

$dbconn->IsConnected()
If youre host gives you just a DSN, you can pass a URI to Connect:
database://username:password@localhost/databasename

Prepared by: Michael Fatica mike@fatica.net

Running Queries
$sql = select * from tblUsers where
username=$username and password=$password;
$rs = $db_conn->Execute($sql);
while(!$rs->EOF()){
echo $rs->Fields(username) . <br />;
echo $rs->Fields(password) . <br />;
$rs->MoveNext();
}
Prepared by: Michael Fatica mike@fatica.net

Inserts and updates


Option 1: Just pass the sql Execute
$db_conn->Execute(insert into tblUsers );

Option 2:
Use AutoExecute (See also GetUpdateSQL
and GetInsertSQL)
Ex:
$record[username] = mike;
$record[password] = supersecr8
$db_conn->AutoExecute(tblusers,$record,INSERT)
Prepared by: Michael Fatica mike@fatica.net

Handy Functions of the Recordset


Object
Properties
SQL: the sql that created it
EOF: True of past the last record

Methods
GetAssoc, GetArray and GetRows
Generate object from current position to EOF or
passed value

GetMenu
Generates a html select from the recordset
Prepared by: Michael Fatica mike@fatica.net

Moving Around Your Results


MoveNext()
Here there be dragons
Move($to) (Zero based)
MoveFirst()
MoveLast()

Prepared by: Michael Fatica mike@fatica.net

Handy Functions of the Connection


Object
(All called as $db_conn->)

DBDate($date) (Format the date as the


database likes it)
Insert_ID( ) (Gets the last inserted
autoincremented ID)
qstr($s) (Escapes strings according to
the DB preferences)

Prepared by: Michael Fatica mike@fatica.net

Utility Functions
Recordset Pager (very cool)
$pager = new ADODB_Pager($db_conn,$sql)
$pager->Render()

Export functions
rs2html
rs2tab
rs2csv
Prepared by: Michael Fatica mike@fatica.net

Transactions
$conn->StartTrans();
$conn->Execute($sql);
$conn->Execute($sql2);
$conn->CompleteTrans();
Rolls back all work done in between Start
and Complete if failure occurs
Prepared by: Michael Fatica mike@fatica.net

Caching
Cache this querys results for 25 seconds
$rs = $db_conn->CacheExecute(25,$sql);

Set cache time globally


$db_conn->cacheSecs

Flush the cache


CacheFlush()

Prepared by: Michael Fatica mike@fatica.net

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy