Cakephp 3: find command not working properly

in cake php3, i have created table class related to table(ClientsTable) and i have use this command to get the result
$clients = TableRegistry::get(‘Clients’);
$res = $clients->find()->where([‘storename’ => $storename]);

and this shows data like
.Cake\ORM\Query Object
(
[_hasFields:protected] =>
[_autoFields:protected] =>
[_hydrate:protected] => 1
[_counter:protected] =>
[_eagerLoader:protected] =>
[_beforeFindFired:protected] =>
[_resultsCount:protected] =>
[_connection:protected] => Cake\Database\Connection Object
(
[_config:protected] => Array
(
[driver] => Cake\Database\Driver\Postgres
[persistent] =>
[host] => localhost
[username] => postgres
[password] => 123456
[database] => local_production
[encoding] => utf8
[timezone] => UTC
[flags] => Array
(
)

                [cacheMetadata] => 1
                [log] => 
                [quoteIdentifiers] => 
                [url] => 
                [name] => default
            )

        [_driver:protected] => Cake\Database\Driver\Postgres Object
            (
                [_baseConfig:protected] => Array
                    (
                        [persistent] => 1
                        [host] => localhost
                        [username] => root
                        [password] => 
                        [database] => cake
                        [schema] => public
                        [port] => 5432
                        [encoding] => utf8
                        [timezone] => 
                        [flags] => Array
                            (
                            )

                        [init] => Array
                            (
                            )

                    )

                [_config:protected] => Array
                    (
                        [driver] => Cake\Database\Driver\Postgres
                        [persistent] => 
                        [host] => localhost
                        [username] => postgres
                        [password] => 123456
                        [database] => local_production
                        [encoding] => utf8
                        [timezone] => UTC
                        [flags] => Array
                            (
                            )

                        [cacheMetadata] => 1
                        [log] => 
                        [quoteIdentifiers] => 
                        [url] => 
                        [name] => default
                        [schema] => public
                        [port] => 5432
                        [init] => Array
                            (
                            )

                    )

                [_autoQuoting:protected] => 
                [_connection:protected] => PDO Object
                    (
                    )

                [_startQuote:protected] => "
                [_endQuote:protected] => "
                [_schemaDialect:protected] => Cake\Database\Schema\PostgresSchema Object
                    (
                        [_driver:protected] => Cake\Database\Driver\Postgres Object

RECURSION
)

            )

        [_transactionLevel:protected] => 0
        [_transactionStarted:protected] => 
        [_useSavePoints:protected] => 
        [_logQueries:protected] => 
        [_logger:protected] => 
        [_schemaCollection:protected] => Cake\Database\Schema\CachedCollection Object
            (
                [_cache:protected] => _cake_model_
                [_connection:protected] => Cake\Database\Connection Object

RECURSION
[_dialect:protected] => Cake\Database\Schema\PostgresSchema Object
(
[_driver:protected] => Cake\Database\Driver\Postgres Object
(
[_baseConfig:protected] => Array
(
[persistent] => 1
[host] => localhost
[username] => root
[password] =>
[database] => cake
[schema] => public
[port] => 5432
[encoding] => utf8
[timezone] =>
[flags] => Array
(
)

                                        [init] => Array
                                            (
                                            )

                                    )

                                [_config:protected] => Array
                                    (
                                        [driver] => Cake\Database\Driver\Postgres
                                        [persistent] => 
                                        [host] => localhost
                                        [username] => postgres
                                        [password] => 123456
                                        [database] => local_production
                                        [encoding] => utf8
                                        [timezone] => UTC
                                        [flags] => Array
                                            (
                                            )

                                        [cacheMetadata] => 1
                                        [log] => 
                                        [quoteIdentifiers] => 
                                        [url] => 
                                        [name] => default
                                        [schema] => public
                                        [port] => 5432
                                        [init] => Array
                                            (
                                            )

                                    )

                                [_autoQuoting:protected] => 
                                [_connection:protected] => PDO Object
                                    (
                                    )

                                [_startQuote:protected] => "
                                [_endQuote:protected] => "
                                [_schemaDialect:protected] => Cake\Database\Schema\PostgresSchema Object

RECURSION
)

                    )

            )

    )

[_type:protected] => select
[_parts:protected] => Array
    (
        [delete] => 1
        [update] => Array
            (
            )

        [set] => Array
            (
            )

        [insert] => Array
            (
            )

        [values] => Array
            (
            )

        [select] => Array
            (
            )

        [distinct] => 
        [modifier] => Array
            (
            )

        [from] => Array
            (
            )

        [join] => Array
            (
            )

        [where] => Cake\Database\Expression\QueryExpression Object
            (
                [_conjunction:protected] => AND
                [_conditions:protected] => Array
                    (
                        [0] => Cake\Database\Expression\Comparison Object
                            (
                                [_value:protected] => production
                                [_type:protected] => string
                                [_operator:protected] => =
                                [_field:protected] => storename
                            )

                    )

                [_typeMap:protected] => Cake\Database\TypeMap Object
                    (
                        [_defaults:protected] => Array
                            (
                                [Clients__id] => integer
                                [Clients.id] => integer
                                [id] => integer
                                [Clients__storename] => string
                                [Clients.storename] => string
                                [storename] => string
                                [Clients__firstname] => string
                                [Clients.firstname] => string
                                [firstname] => string
                                [Clients__lastname] => string
                                [Clients.lastname] => string
                                [lastname] => string
                                [Clients__email] => string
                                [Clients.email] => string
                                [email] => string
                                [Clients__company_name] => string
                                [Clients.company_name] => string
                                [company_name] => string
                                [Clients__phone] => string
                                [Clients.phone] => string
                                [phone] => string
                                [Clients__created_date] => integer
                                [Clients.created_date] => integer
                                [created_date] => integer
                                [Clients__account_type] => string
                                [Clients.account_type] => string
                                [account_type] => string
                                [Clients__payment_gateway] => string
                                [Clients.payment_gateway] => string
                                [payment_gateway] => string
                                [Clients__account_name] => string
                                [Clients.account_name] => string
                                [account_name] => string
                                [Clients__address] => string
                                [Clients.address] => string
                                [address] => string
                                [Clients__address2] => string
                                [Clients.address2] => string
                                [address2] => string
                                [Clients__city] => string
                                [Clients.city] => string
                                [city] => string
                                [Clients__postalzip] => string
                                [Clients.postalzip] => string
                                [postalzip] => string
                                [Clients__country] => integer
                                [Clients.country] => integer
                                [country] => integer
                                [Clients__state] => string
                                [Clients.state] => string
                                [state] => string
                                [Clients__currency] => string
                                [Clients.currency] => string
                                [currency] => string
                                [Clients__enabled] => integer
                                [Clients.enabled] => integer
                                [enabled] => integer
                                [Clients__reference] => text
                                [Clients.reference] => text
                                [reference] => text
                                [Clients__parent_client_id] => integer
                                [Clients.parent_client_id] => integer
                                [parent_client_id] => integer
                                [Clients__clone_from_client_id] => integer
                                [Clients.clone_from_client_id] => integer
                                [clone_from_client_id] => integer
                                [Clients__last_modified_time] => timestamp
                                [Clients.last_modified_time] => timestamp
                                [last_modified_time] => timestamp
                            )

                        [_types:protected] => Array
                            (
                            )

                    )

            )

        [group] => Array
            (
            )

        [having] => 
        [order] => 
        [limit] => 
        [offset] => 
        [union] => Array
            (
            )

        [epilog] => 
    )

[_dirty:protected] => 1
[_resultDecorators:protected] => Array
    (
    )

[_iterator:protected] => 
[_valueBinder:protected] => 
[_functionsBuilder:protected] => 
[_useBufferedResults:protected] => 1
[_selectTypeMap:protected] => 
[_typeCastAttached:protected] => 
[_typeMap:protected] => Cake\Database\TypeMap Object
    (
        [_defaults:protected] => Array
            (
                [Clients__id] => integer
                [Clients.id] => integer
                [id] => integer
                [Clients__storename] => string
                [Clients.storename] => string
                [storename] => string
                [Clients__firstname] => string
                [Clients.firstname] => string
                [firstname] => string
                [Clients__lastname] => string
                [Clients.lastname] => string
                [lastname] => string
                [Clients__email] => string
                [Clients.email] => string
                [email] => string
                [Clients__company_name] => string
                [Clients.company_name] => string
                [company_name] => string
                [Clients__phone] => string
                [Clients.phone] => string
                [phone] => string
                [Clients__created_date] => integer
                [Clients.created_date] => integer
                [created_date] => integer
                [Clients__account_type] => string
                [Clients.account_type] => string
                [account_type] => string
                [Clients__payment_gateway] => string
                [Clients.payment_gateway] => string
                [payment_gateway] => string
                [Clients__account_name] => string
                [Clients.account_name] => string
                [account_name] => string
                [Clients__address] => string
                [Clients.address] => string
                [address] => string
                [Clients__address2] => string
                [Clients.address2] => string
                [address2] => string
                [Clients__city] => string
                [Clients.city] => string
                [city] => string
                [Clients__postalzip] => string
                [Clients.postalzip] => string
                [postalzip] => string
                [Clients__country] => integer
                [Clients.country] => integer
                [country] => integer
                [Clients__state] => string
                [Clients.state] => string
                [state] => string
                [Clients__currency] => string
                [Clients.currency] => string
                [currency] => string
                [Clients__enabled] => integer
                [Clients.enabled] => integer
                [enabled] => integer
                [Clients__reference] => text
                [Clients.reference] => text
                [reference] => text
                [Clients__parent_client_id] => integer
                [Clients.parent_client_id] => integer
                [parent_client_id] => integer
                [Clients__clone_from_client_id] => integer
                [Clients.clone_from_client_id] => integer
                [clone_from_client_id] => integer
                [Clients__last_modified_time] => timestamp
                [Clients.last_modified_time] => timestamp
                [last_modified_time] => timestamp
            )

        [_types:protected] => Array
            (
            )

    )

[_repository:protected] => App\Model\Table\ClientsTable Object
    (
        [_table:protected] => clients
        [_alias:protected] => Clients
        [_connection:protected] => Cake\Database\Connection Object
            (
                [_config:protected] => Array
                    (
                        [driver] => Cake\Database\Driver\Postgres
                        [persistent] => 
                        [host] => localhost
                        [username] => postgres
                        [password] => 123456
                        [database] => local_production
                        [encoding] => utf8
                        [timezone] => UTC
                        [flags] => Array
                            (
                            )

                        [cacheMetadata] => 1
                        [log] => 
                        [quoteIdentifiers] => 
                        [url] => 
                        [name] => default
                    )

                [_driver:protected] => Cake\Database\Driver\Postgres Object
                    (
                        [_baseConfig:protected] => Array
                            (
                                [persistent] => 1
                                [host] => localhost
                                [username] => root
                                [password] => 
                                [database] => cake
                                [schema] => public
                                [port] => 5432
                                [encoding] => utf8
                                [timezone] => 
                                [flags] => Array
                                    (
                                    )

                                [init] => Array
                                    (
                                    )

                            )

                        [_config:protected] => Array
                            (
                                [driver] => Cake\Database\Driver\Postgres
                                [persistent] => 
                                [host] => localhost
                                [username] => postgres
                                [password] => 123456
                                [database] => local_production
                                [encoding] => utf8
                                [timezone] => UTC
                                [flags] => Array
                                    (
                                    )

                                [cacheMetadata] => 1
                                [log] => 
                                [quoteIdentifiers] => 
                                [url] => 
                                [name] => default
                                [schema] => public
                                [port] => 5432
                                [init] => Array
                                    (
                                    )

                            )

                        [_autoQuoting:protected] => 
                        [_connection:protected] => PDO Object
                            (
                            )

                        [_startQuote:protected] => "
                        [_endQuote:protected] => "
                        [_schemaDialect:protected] => Cake\Database\Schema\PostgresSchema Object
                            (
                                [_driver:protected] => Cake\Database\Driver\Postgres Object

RECURSION
)

                    )

                [_transactionLevel:protected] => 0
                [_transactionStarted:protected] => 
                [_useSavePoints:protected] => 
                [_logQueries:protected] => 
                [_logger:protected] => 
                [_schemaCollection:protected] => Cake\Database\Schema\CachedCollection Object
                    (
                        [_cache:protected] => _cake_model_
                        [_connection:protected] => Cake\Database\Connection Object

RECURSION
[_dialect:protected] => Cake\Database\Schema\PostgresSchema Object
(
[_driver:protected] => Cake\Database\Driver\Postgres Object
(
[_baseConfig:protected] => Array
(
[persistent] => 1
[host] => localhost
[username] => root
[password] =>
[database] => cake
[schema] => public
[port] => 5432
[encoding] => utf8
[timezone] =>
[flags] => Array
(
)

                                                [init] => Array
                                                    (
                                                    )

                                            )

                                        [_config:protected] => Array
                                            (
                                                [driver] => Cake\Database\Driver\Postgres
                                                [persistent] => 
                                                [host] => localhost
                                                [username] => postgres
                                                [password] => 123456
                                                [database] => local_production
                                                [encoding] => utf8
                                                [timezone] => UTC
                                                [flags] => Array
                                                    (
                                                    )

                                                [cacheMetadata] => 1
                                                [log] => 
                                                [quoteIdentifiers] => 
                                                [url] => 
                                                [name] => default
                                                [schema] => public
                                                [port] => 5432
                                                [init] => Array
                                                    (
                                                    )

                                            )

                                        [_autoQuoting:protected] => 
                                        [_connection:protected] => PDO Object
                                            (
                                            )

                                        [_startQuote:protected] => "
                                        [_endQuote:protected] => "
                                        [_schemaDialect:protected] => Cake\Database\Schema\PostgresSchema Object

RECURSION
)

                            )

                    )

please help me in finding the data from database

The query builder doesn’t execute the actual sql command immediately; This is useful, because you can just append rules to it all throughout your method and only execute it at the end.

To execute the query, you have to use either ->first(), ->all() or toArray(). For instance:

$res = $clients->find()->where(['storename' => $storename])->first();

Or you could do things like:

$res = $clients->find()->where(['storename' => $storename]);

Bunch of other code...

$res->first();

But if you don’t execute it this way, you’ll just get irrelevant query information instead of its result.

2 Likes