Welcome Guest, Not a member yet? Register   Sign In
Basic understanding of returned values
#1

Hi, 

i've create a first modell
with in this functon
"public function users_get_by_id(int $id, array $fields=array())
{
if(empty($fields)){ return $this->find($id); }
else
{ return $this->select($fields)->where('id', $id); }
}"

in controller i get and print out the returned values

" $data = $this->UsersModel->users_get_by_id(user_id(),['username','department_main']);
echo"<pre>";
print_r($data);"

now i wondering, why in my $data are not only the values from the tables/fields called by the "users_get_by_id" function. There are a lot more informations.

Example print_r($data)
"App\Models\UsersModel Object
(
[pager] =>
[db:protected] => CodeIgniter\Database\MySQLi\Connection Object
(
[DSN:protected] =>
[port:protected] => 3306
[hostname:protected] => ....
[username:protected] => ...
[password:protected] => ...
[database:protected] =>....
[DBDriver] => MySQLi
[subdriver:protected] =>
[DBPrefix:protected] =>
[pConnect:protected] =>
[DBDebug:protected] => 1
[charset:protected] => utf8mb4
[DBCollat:protected] => utf8mb4_general_ci
[swapPre:protected] =>
[encrypt:protected] =>
[compress:protected] =>
[strictOn:protected] =>
[failover:protected] => Array
(
)

[lastQuery:protected] => CodeIgniter\Database\Query Object
(
[originalQueryString:protected] => UPDATE `users` SET `last_active` = :last_active:
WHERE `id` = :id:
[finalQueryString:protected] => UPDATE `users` SET `last_active` = '2024-12-26 08:21:46'
WHERE `id` = 4
[binds:protected] => Array
(
[last_active] => Array
(
[0] => 2024-12-26 08:21:46
[1] => 1
)

[id] => Array
(
[0] => 4
[1] => 1
)

)

[bindMarker:protected] => ?
[startTime:protected] => 1735197706.5346
[endTime:protected] => 1735197706.6206
[errorCode:protected] =>
[errorString:protected] =>
[db] => CodeIgniter\Database\MySQLi\Connection Object
*RECURSION*
)

[connID] => mysqli Object
(
[affected_rows] => 1
[client_info] => mysqlnd 8.2.25
[client_version] => 80225
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)

[field_count] => 0
[host_info] => ...:3306 via TCP/IP
[info] => Rows matched: 1 Changed: 1 Warnings: 0
[insert_id] => 0
[server_info] => 8.0.33
[server_version] => 80033
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 191645650
[warning_count] => 0
)

[resultID] => 1
[protectIdentifiers] => 1
[reservedIdentifiers:protected] => Array
(
[0] => *
)

[escapeChar] => `
[likeEscapeStr] => ESCAPE '%s'
[likeEscapeChar] => !
[pregEscapeChar:protected] => Array
(
[1] => `
[0] => `
[3] => `
[2] => `
)

[dataCache] => Array
(
)

[connectTime:protected] => 1735197706.5289
[connectDuration:protected] => 0.0016748905181885
[pretend:protected] =>
[transEnabled] => 1
[transStrict] => 1
[transDepth:protected] => 0
[transStatus:protected] => 1
[transFailure:protected] =>
[transException:protected] =>
[aliasedTables:protected] => Array
(
)

[queryClass:protected] => CodeIgniter\Database\Query
[dateFormat:protected] => Array
(
[date] => Y-m-d
[datetime] => Y-m-d H:iConfused
[datetime-ms] => Y-m-d H:iConfused.v
[datetime-us] => Y-m-d H:iConfused.u
[time] => H:iConfused
)

[deleteHack] => 1
[mysqli] => mysqli Object
(
[affected_rows] => 1
[client_info] => mysqlnd 8.2.25
[client_version] => 80225
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)

[field_count] => 0
[host_info] => ... via TCP/IP
[info] => Rows matched: 1 Changed: 1 Warnings: 0
[insert_id] => 0
[server_info] => 8.0.33
[server_version] => 80033
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 191645650
[warning_count] => 0
)

[resultMode] => 0
[numberNative] =>
)

[insertID:protected] => 0
[DBGroup:protected] => globalDB
[returnType:protected] => array
[tempReturnType:protected] => array
[casts:protected] => Array
(
)

[castHandlers:protected] => Array
(
)

[converter:protected] =>
[protectFields:protected] => 1
[allowedFields:protected] => Array
(
[0] => username
[1] => status
[2] => status_message
[3] => active
[4] => last_active
)

[useTimestamps:protected] =>
[dateFormat:protected] => datetime
[createdField:protected] => created_at
[updatedField:protected] => updated_at
[useSoftDeletes:protected] => 1
[tempUseSoftDeletes:protected] => 1
[deletedField:protected] => deleted_at
[allowEmptyInserts:protected] =>
[updateOnlyChanged:protected] => 1
[validationRules:protected] => Array
(
)

[validationMessages:protected] => Array
(
)

[skipValidation:protected] =>
[cleanValidationRules:protected] => 1
[validation:protected] =>
[allowCallbacks:protected] => 1
[tempAllowCallbacks:protected] => 1
[beforeInsert:protected] => Array
(
)

[afterInsert:protected] => Array
(
)

[beforeUpdate:protected] => Array
(
)

[afterUpdate:protected] => Array
(
)

[beforeInsertBatch:protected] => Array
(
)

[afterInsertBatch:protected] => Array
(
)

[beforeUpdateBatch:protected] => Array
(
)

[afterUpdateBatch:protected] => Array
(
)

[beforeFind:protected] => Array
(
)

[afterFind:protected] => Array
(
)

[beforeDelete:protected] => Array
(
)

[afterDelete:protected] => Array
(
)

[table:protected] => users
[primaryKey:protected] => id
[useAutoIncrement:protected] => 1
[builder:protected] => CodeIgniter\Database\MySQLi\Builder Object
(
[resetDeleteData:protected] =>
[QBSelect:protected] => Array
(
[0] => username
[1] => department_main
)

[QBDistinct:protected] =>
[QBFrom:protected] => Array
(
[0] => `users`
)

[QBJoin:protected] => Array
(
)

[QBWhere:protected] => Array
(
[0] => Array
(
[condition] => id = :id:
[escape] => 1
)

)

[QBGroupBy] => Array
(
)

[QBHaving:protected] => Array
(
)

[QBKeys:protected] => Array
(
)

[QBLimit:protected] =>
[QBOffset:protected] =>
[QBOrderBy] => Array
(
)

[QBUnion:protected] => Array
(
)

[QBNoEscape] => Array
(
[0] => 1
[1] => 1
)

[QBSet:protected] => Array
(
)

[QBWhereGroupStarted:protected] =>
[QBWhereGroupCount:protected] => 0
[QBIgnore:protected] =>
[QBOptions:protected] =>
[db:protected] => CodeIgniter\Database\MySQLi\Connection Object
(
[DSN:protected] =>
[port:protected] => 3306
[hostname:protected] => 10.35.47.127:3306
[username:protected] => k84694_4u
[password:protected] => 4hkf$;3M37FaB
[database:protected] => k84694_4u
[DBDriver] => MySQLi
[subdriver:protected] =>
[DBPrefix:protected] =>
[pConnect:protected] =>
[DBDebug:protected] => 1
[charset:protected] => utf8mb4
[DBCollat:protected] => utf8mb4_general_ci
[swapPre:protected] =>
[encrypt:protected] =>
[compress:protected] =>
[strictOn:protected] =>
[failover:protected] => Array
(
)

[lastQuery:protected] => CodeIgniter\Database\Query Object
(
[originalQueryString:protected] => UPDATE `users` SET `last_active` = :last_active:
WHERE `id` = :id:
[finalQueryString:protected] => UPDATE `users` SET `last_active` = '2024-12-26 08:21:46'
WHERE `id` = 4
[binds:protected] => Array
(
[last_active] => Array
(
[0] => 2024-12-26 08:21:46
[1] => 1
)

[id] => Array
(
[0] => 4
[1] => 1
)

)

[bindMarker:protected] => ?
[startTime:protected] => 1735197706.5346
[endTime:protected] => 1735197706.6206
[errorCode:protected] =>
[errorString:protected] =>
[db] => CodeIgniter\Database\MySQLi\Connection Object
*RECURSION*
)

[connID] => mysqli Object
(
[affected_rows] => 1
[client_info] => mysqlnd 8.2.25
[client_version] => 80225
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)

[field_count] => 0
[host_info] => ::::3306 via TCP/IP
[info] => Rows matched: 1 Changed: 1 Warnings: 0
[insert_id] => 0
[server_info] => 8.0.33
[server_version] => 80033
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 191645650
[warning_count] => 0
)

[resultID] => 1
[protectIdentifiers] => 1
[reservedIdentifiers:protected] => Array
(
[0] => *
)

[escapeChar] => `
[likeEscapeStr] => ESCAPE '%s'
[likeEscapeChar] => !
[pregEscapeChar:protected] => Array
(
[1] => `
[0] => `
[3] => `
[2] => `
)

[dataCache] => Array
(
)

[connectTime:protected] => 1735197706.5289
[connectDuration:protected] => 0.0016748905181885
[pretend:protected] =>
[transEnabled] => 1
[transStrict] => 1
[transDepth:protected] => 0
[transStatus:protected] => 1
[transFailure:protected] =>
[transException:protected] =>
[aliasedTables:protected] => Array
(
)

[queryClass:protected] => CodeIgniter\Database\Query
[dateFormat:protected] => Array
(
[date] => Y-m-d
[datetime] => Y-m-d H:iConfused
[datetime-ms] => Y-m-d H:iConfused.v
[datetime-us] => Y-m-d H:iConfused.u
[time] => H:iConfused
)

[deleteHack] => 1
[mysqli] => mysqli Object
(
[affected_rows] => 1
[client_info] => mysqlnd 8.2.25
[client_version] => 80225
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)

[field_count] => 0
[host_info] => ....:3306 via TCP/IP
[info] => Rows matched: 1 Changed: 1 Warnings: 0
[insert_id] => 0
[server_info] => 8.0.33
[server_version] => 80033
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 191645650
[warning_count] => 0
)

[resultMode] => 0
[numberNative] =>
)

[tableName:protected] => users
[randomKeyword:protected] => Array
(
[0] => RAND()
[1] => RAND(%d)
)

[countString:protected] => SELECT COUNT(*) AS
[binds:protected] => Array
(
[id] => Array
(
[0] => 4
[1] => 1
)

)

[bindsKeyCount:protected] => Array
(
)

[canLimitDeletes:protected] => 1
[canLimitWhereUpdates:protected] => 1
[supportedIgnoreStatements:protected] => Array
(
[update] => IGNORE
[insert] => IGNORE
[delete] => IGNORE
)

[testMode:protected] =>
[joinTypes:protected] => Array
(
[0] => LEFT
[1] => RIGHT
[2] => OUTER
[3] => INNER
[4] => LEFT OUTER
[5] => RIGHT OUTER
)

[isLiteralStr:protected] => Array
(
)

[pregOperators:protected] => Array
(
)

[escapeChar:protected] => `
)

[tempData:protected] => Array
(
)

[escape:protected] => Array
(
)

[builderMethodsNotAvailable:CodeIgniter\Model:private] => Array
(
[0] => getCompiledInsert
[1] => getCompiledSelect
[2] => getCompiledUpdate
)

)"


Where are they from, is it normaly in ci4?

How can i reduse the returned value only to the values from the function?

By the way what it means and effects with the prepend parts like "[db:protected]" etc?

Thanks a lot to make it clear for me.
Reply
#2

You need to return a result.

CodeIgniter 4 Users Guide - Working with Databases - Quick Start: Usage Examples
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB