Let's take a look at how we can select some data.
Selecting and Updating Data
We can load and change any record using ActiveRecord easily. Let's have a look at
the following example:
include("adodb/adodb.inc.php");
include('adodb/adodb-active-record.inc.php');
$conn =ADONewConnection('mysql');
$conn->connect("localhost","user","password","test") ;
ADODB_Active_Record::setDatabaseAdapter($conn);
class User extends ADODB_Active_Record {}
$user = new User();
$user->load("id=10");//load the record where the id is 10
echo $user->name;
$user->name= "Afif Mohiuddin";//now update
$user->save();//and save the previously loaded record
?>
So that's fairly easy. When you call the load() method with any expression, the
record will be loaded into the object itself. Then you can make any change and finally
save it. ActiveRecord is extremely charming to work with.
Database in an OOP Way
[ 194 ]
Summary
You finished reading a chapter devoted for total DB access using the OOP way.
There are lot other interesting projects like Propel (http://propel.phpdb.org/
trac/) as Object Relational Mapping library for PHP developers, Creole
(http://creole.phpdb.org/trac/) as a DAL, ActiveRecord library from
CodeIgniter framework (http://www.
Pages:
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210