Support
- Advanced Backup
- Client Side
- Cloud Enterprise
- ColdFusion
- Control Panel
- cPanel
- Customer Portal
- DNS Information
- Dedicated Servers
- DirectAdmin
- Domain Name
- dotDefender
- Dreamweaver
- FileCatalyst
- Front Page
- FTP
- General Information
- Hosted Exchange & SharePoint
- IIS6
- IIS7
- Juniper Netscreen Firewalls
- Linux
- List Server
- MIVA Merchant
- MySQL
- Patching / Server Updates
- phpMyAdmin
- Plesk
- Policies and Procedures
- Premium Spam Filtering
- Programming
- 500 Error
- Accessdb 1
- Accessdb 2
- Aspmail
- Aspsqlinjection
- Aspupload
- Connectionstrings
- Faq Windows
- Locked Db
- Programming
- Use a JSP (Java) Redirect Script
- Conditional 301 Redirect
- Using ADOdb to Build a Database Agnostic PHP Application
- Store PHP Session Data in a Database with ADODB
- Use JQueryUI Sortable to Manipulate Sort Order in a Database Table
- Use PHP GD to Resize Images on Upload
- Add a Facebook Like Button to Your Website
- Add a Twitter Tweet Button to Your Website
- Enhance User Experience with JavaScript Form Validation
- Get Started Integrating FaceBook with the PHP-SDK
- Get Started with the Twitter API
- Ruby on Rails
- Search Engine Submission
- SharePoint 3
- SharePoint 2010
- SiteDesigner
- SmarterMail 3
- SmarterMail 4
- SmarterMail 5
- SmarterMail 6
- SmarterMail 7
- SmarterStats
- SmarterTrack
- SQL Server
- Secure Socket Layer (SSL)
- Uploading Your Website
- Video Tutorials
- Windows Server 2003
- Windows Server 2008
- Web Design
- WordPress
- Advanced Monitoring
- MediaWiki
- Enkompass
- Microsoft Outlook 2010
- Android
- Outlook Web Access
- Critical Availability Service
- NAS Data Transfer
- Customer Portal Demos
- Joomla
- Moodle
- Cloud Dedicated
- Gallery CMS
- phpBB
- Standard Monitoring
- Righteous Restore
- NAS (Network Attached Storage)
- Networking
- SmarterMail 8
- PCI Security Scan
- LinkTiger
- Windows Cloud VPS
- Linux Cloud VPS
- Linux VPS
- Windows VPS
- Hyper V
- ENSIM
- Alert Logic
- Webmin
- e107
- Vbulletin
- VPN
- Visual Vault
- Mozilla Thunderbird
- PyroCMS
- Active Directory
- Vmware Related
- Drupal
Building a Database Agnostic PHP Application With ADOdb
This article explains what ADOdb is and provides examples on how it can be used with PHP to build an application that connects to any supported database server.
What is ADOdb
ADOdb is and open source database abstraction library for PHP. The purpose of a database abstraction library is to create uniformity in communicating with multiple database servers. Think of it this way, for your application to support multiple databases it would need different lines of code to perform the same functions on each. With an abstraction library the application only needs one set of code to communicate with any database the library supports. This drastically increases the number of database server options available for your PHP application.
Active Record
ADOdb also supports Active Record. Active Record uses Object Relation Mapping (ORM) to communicate with your database through PHP data objects by mapping them to tables and rows. This method removes the need to write SQL queries speeding up application development.
Hosting Platform
ADOdb is a PHP library that can be used on any Hosting.com platform service with PHP and all pre-installed database servers.
Installation
Installing ADOdb can be completed in three steps:
- Obtain the latest version of ADOdb.
- Copy the ADOdb folder to a directory within your application.
- Include the adodb.inc.php in your application's configuration file.
Usage Examples
Connection Example:
<?php
include('adodb/adodb.inc.php');
$db = ADONewConnection('mysql'); # eg 'mysql' or 'postgres'
$db->debug = true;
$db->Connect($server, $user, $password, $database);
?>
Sample Query:
<?php
$rs = $db->Execute('select fname,lname from table');
print "<pre>";
print_r($rs->GetRows());
print "</pre>";
?>
Active Record Usage:
<?php
include('adodb/adodb.inc.php');
include('adodb/adodb-active-record.inc.php');
$db = ADONewConnection('mysql'); # eg 'mysql' or 'postgres'
$db->debug = true;
$db->Connect($server, $user, $password, $database);
ADOdb_Active_Record::SetDatabaseAdapter($db);
ADODB_Active_Record::$_quoteNames = true;
#the following example use a table that was created with this statement
$db->Execute("CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL auto_increment,
`fname` varchar(100) NOT NULL default '',
`lname` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
");
#create an empty class to work with our new table
class users extends ADOdb_Active_Record {
var $_table = 'users';
}
$users = new users();
#insert a new record
$users->fname = 'Ronald';
$users->lname = 'Reagan';
$users->save();
# $users->id is now equal to the last inserted id. For this example we will assume the id is 1.
#update a record
$users->id = 1;
$users->fname = 'Nancy';
$users->save();
#select a single record
$users->load('id=1');
#now the users object contains the full row of data where id = 1.
?>
