ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:active_record

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
v5:userguide:active_record [2016/01/13 02:31]
mnewnham ↷ Links adapted because of a move operation
v5:userguide:active_record [2019/05/08 16:32] (current)
dregad [Setting the Table Name] ADODB_ASSOC_CASE not $ADODB_ASSOC_CASE
Line 152: Line 152:
 We provide two ways to define your own table: We provide two ways to define your own table:
  
-1. Use a constructor parameter to override the default table naming behaviour.+  - Use a constructor parameter to override the default table naming behaviour. ​<code php> 
 +class person extends ADOdb_Active_Record {} 
 +$person = new person('​People'​);​ 
 +</​code>​ 
 +  - Define it in a class declaration:​ <code php> 
 +class person extends ADOdb_Active_Record 
 +
 +    var $_table = '​People';​ 
 +
 +$person = new person(); 
 +</​code>​
  
- class person extends ADOdb_Active_Record{} +==== ADODB_ASSOC_CASE ====
- $person ​new person('​People'​);​ +
-2. Define it in a class declaration:​+
  
- class person extends ADOdb_Active_Record +This allows you to control the case of field names and properties. For example, in Oracle all field names are uppercase by default, so you can force them to lowercase using ''​define('​ADODB_ASSOC_CASE',​ ADODB_ASSOC_CASE_LOWER);''​.
-+
- var $_table = 'People'+
-+
- $person = new person(); +
-$ADODB_ASSOC_CASE+
  
-This allows you to control the case of field names and properties. For exampleall field names in Oracle are upper-case by defaultSo you can force field names to be lowercase using $ADODB_ASSOC_CASE. Legal values are as follows:+For further details on valid values ​and usagesee [[v5:​reference:​adodb_assoc_case]] reference.
  
- 0: lower-case +<code php> 
- 1: upper-case +// ADODB_ASSOC_CASE ==  ADODB_ASSOC_CASE_LOWER
- 2: native-case +
-So to force all Oracle field names to lower-case, use +
- +
-$ADODB_ASSOC_CASE = 0;+
 $person = new person('​People'​);​ $person = new person('​People'​);​
 $person->​name = '​Lily';​ $person->​name = '​Lily';​
-$ADODB_ASSOC_CASE = 2;+ 
 +// ADODB_ASSOC_CASE ==  ADODB_ASSOC_CASE_UPPER
 $person2 = new person('​People'​);​ $person2 = new person('​People'​);​
 $person2->​NAME = '​Lily';​ $person2->​NAME = '​Lily';​
-Also see $ADODB_ASSOC_CASE.+</​code>​
  
-ADOdb_Active_Record::​Save()+==== ADOdb_Active_Record::​Save() ​====
  
 Saves a record by executing an INSERT or UPDATE SQL statement as appropriate. Saves a record by executing an INSERT or UPDATE SQL statement as appropriate.
Line 188: Line 188:
 Returns 0 on failed UPDATE, and 1 on UPDATE if data has changed, and -1 if no data was changed, so no UPDATE statement was executed. Returns 0 on failed UPDATE, and 1 on UPDATE if data has changed, and -1 if no data was changed, so no UPDATE statement was executed.
  
-ADOdb_Active_Record::​Replace()+==== ADOdb_Active_Record::​Replace() ​====
  
 ADOdb supports replace functionality,​ whereby the record is inserted if it does not exists, or updated otherwise. ADOdb supports replace functionality,​ whereby the record is inserted if it does not exists, or updated otherwise.
Line 210: Line 210:
 </​code>​ </​code>​
  
-ADOdb_Active_Record::​Find($whereOrderBy,​ $bindarr=false,​ $pkeyArr=false)+==== ADOdb_Active_Record::​Find($whereOrderBy,​ $bindarr=false,​ $pkeyArr=false) ​====
  
 We want to retrieve an array of active records based on some search criteria. For example: We want to retrieve an array of active records based on some search criteria. For example:
 <code php> <code php>
 class person extends ADOdb_Active_Record { class person extends ADOdb_Active_Record {
-var $_table = '​people';​+    ​var $_table = '​people';​
 } }
  
Line 221: Line 221:
 $peopleArray = $person->​Find("​name like ? order by age", array('​Sm%'​));​ $peopleArray = $person->​Find("​name like ? order by age", array('​Sm%'​));​
 </​code>​ </​code>​
 +
 ===== Quoting Identifiers ===== ===== Quoting Identifiers =====
  
v5/userguide/active_record.txt · Last modified: 2019/05/08 16:32 by dregad