PEAR Manual
Prev |  | Next

# ->get()

->get() -- Simple Get (Select) request

## Synopsis

``int $DB_DataObject->get` (mixed Key or Value [, mixed value])`

## Description

Get a result using key, value. Returns Number of rows located (usually 1) for success, and puts all the table columns into this classes variables. If only one parameter is used, it is assumed that first parameter is a value and get() will use the primary key.

## Parameter

- `mixed $key or $value` - column (or value if only one parameter)

- `mixed $value` - value

## Return value

`int` - Number of rows

## Throws

Table 33-1. Possible PEAR_Error values

Error code | Error message | Meaning | Solution
--- | --- | --- | ---
DB_DATAOBJECT_ERROR_INVALIDCONFIG | "No Keys available for $table" |  |
DB_DATAOBJECT_ERROR_INVALIDARGS | "No Value specified for get" |  |

## Note

This function can not be called statically.

You should avoid calling get on the same object instance twice, as this will result in unexpected results.

## Example

Example 33-1. Simple fetch of data based on Primary Key
    $person = new DataObjects_Person;
    $person->get(12);
    print_r($person);

Example 33-2. Resulting SQL
    SELECT * FROM person WHERE id=12

Example 33-3. Simple fetch of data based on Key and Value
    $person = new DataObjects_Person;
    $person->get('email','test@example.com');
    print_r($person);

Example 33-4. Resulting SQL
    SELECT * FROM person WHERE email='test@example.com'

Example 33-5. Results of example code
    Object (DataObjects_Person) =>
        [N] => 1
        [id] => 12
        [group] => 5
        [has_glasses] => 1
        [name] => 'fred blogs'
        [password] => '**testing'
        [email] => 'test@example.com'

Prev | Home | Next
DB_DataObject::factory() | Up | DB_DataObject::staticGet()