ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:substr

Differences

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

Link to this comparison view

Next revision
Previous revision
v5:reference:connection:substr [2016/04/10 02:58] – created mnewnhamv5:reference:connection:substr [2016/04/10 23:42] (current) mnewnham
Line 4: Line 4:
 **From Version 5.21.0-beta-2** **From Version 5.21.0-beta-2**
 == Syntax == == Syntax ==
-  string addAttribute(+  string substr(
       string $fieldName,       string $fieldName,
-      integer $offset+      int $startPoint
-      optional integer $length+      optional int $length
       )       )
 </WRAP> </WRAP>
-===== Desscription =====+===== Description =====
 The method ''substr()'' creates an SQL statement that returns the substring of a specified string field.  The method ''substr()'' creates an SQL statement that returns the substring of a specified string field. 
  ===== Parameters =====  ===== Parameters =====
Line 16: Line 16:
 The fieldname to be substringed. The fieldname must be accessible as part of the current SQL statement. The fieldname to be substringed. The fieldname must be accessible as part of the current SQL statement.
  
-==== $startpoint ====+==== $startPoint ====
 The starting point within the original string for the substring to begin. Offsets in SQL statements are 1 based, rather than the normal 0 (Zero) based offsets used in PHP. The starting point within the original string for the substring to begin. Offsets in SQL statements are 1 based, rather than the normal 0 (Zero) based offsets used in PHP.
  
Line 26: Line 26:
 <code php> <code php>
 /* /*
-* To return the first code plus the first 20 characters of a description.+* To return the an associative array of codes plus  
 +the first 20 characters of a description.
 */ */
 $sql = "SELECT code, {$db->substr('description',1,20)} FROM some_table"; $sql = "SELECT code, {$db->substr('description',1,20)} FROM some_table";
 $data = $db->getAssoc($sql);  $data = $db->getAssoc($sql); 
 </code> </code>
 +
 +===== Negative Offsets =====
 +Not all databases support the use of negative offsets (to return values based on the end of the string), so use in portable applications is not recommended.
  
  
v5/reference/connection/substr.1460249916.txt.gz · Last modified: 2017/04/21 11:32 (external edit)