ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:code_snippet_1

Setting the Database Connection

The first step to using ADOdb_Active_Record is to set the default connection that an ADOdb_Active_Record objects will use to connect to a database. In addition, we will also create a temporary table to hold the data. The same table is used for each of the examples.

require_once 'adodb/adodb-active-record.inc.php';
 
$db = NewADOConnection('mysql://root:pwd@localhost/dbname');
 
/*
* Now link the database to the Active Record Class
*/
ADOdb_Active_Record::SetDatabaseAdapter($db);
 
 
/*
* Create the temporary table
*/
$db->Execute("CREATE TEMPORARY TABLE `persons` (
             `id` int(10) unsigned NOT NULL auto_increment,
             `name_first` varchar(100) NOT NULL default '',
             `name_last` varchar(100) NOT NULL default '',
             `favorite_color` varchar(100) NOT NULL default '',
             PRIMARY KEY  (`id`)
            ) ENGINE=MyISAM;
            ");
 
 
 
$db->Execute("CREATE TEMPORARY TABLE `children` (
             `id` int(10) unsigned NOT NULL auto_increment,
	     `person_id` int(10) unsigned NOT NULL,
	     `gender` varchar(10) default 'F',
             `name_first` varchar(100) NOT NULL default '',
             `name_last` varchar(100) NOT NULL default '',
             `favorite_pet` varchar(100) NOT NULL default '',
             PRIMARY KEY  (`id`)
            ) ENGINE=MyISAM;
           ");
v5/activerecord/code_snippet_1.txt · Last modified: 2016/01/13 02:15 by mnewnham