ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:substr

This is an old revision of the document!


substr

From Version 5.21.0-beta-2

Syntax
string addAttribute(
    string $fieldName,
    integer $offset,
    optional integer $length
    )

Desscription

The method substr() creates an SQL statement that returns the substring of a specified string field.

Parameters

$fieldName

The fieldname to be substringed. The fieldname must be accessible as part of the current SQL statement.

$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.

$length

If specified, the length of the string to return. If not specified, then the remainder of the string starting at the start point is returned

Usage

/*
* To return the first code plus the first 20 characters of a description.
*/
$sql = "SELECT code, {$db->substr('description',1,20)} FROM some_table";
$data = $db->getAssoc($sql); 
v5/reference/connection/substr.1460249916.txt.gz · Last modified: 2017/04/21 11:32 (external edit)