Num Rows ODBC Codeigniter 3.0.3 No t Working ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: Num Rows ODBC Codeigniter 3.0.3 No t Working ? (/showthread.php?tid=64074) |
Num Rows ODBC Codeigniter 3.0.3 No t Working ? - projack89 - 01-12-2016 Hi All, I have a problem with Codeigniter connectiong to SQL Server 2012. Below my database Configuration $db['DbSms'] = array( 'dsn' => '', 'hostname' => 'Driver={SQL Server};Server=My Local IP', 'username' => 'sa', 'password' => 'my password', 'database' => 'DB_SMS', 'dbdriver' => 'odbc', 'dbprefix' => '', 'pconnect' => TRUE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); Below my script in controller $correct_ip_address = $_SERVER['REMOTE_ADDR']; $query = $this->dbuser->query(" select * from [USERMASTER].[dbo].[tbl_trx_session] where USER_ID ='$USER_ID' AND SESSION_LOGINFLAG='1' AND SESSION_WKIP='$correct_ip_address' "); foreach ($query->result() as $row){ echo $row->USER_ID; echo $row->USER_ID; echo $row->USER_ID; } print_r($query);die; Result print_r CI_DB_odbc_result Object ( [conn_id] => Resource id #53 [result_id] => Resource id #54 [result_array] => Array ( ) [result_object] => Array ( [0] => stdClass Object ( [IDX] => 421567 [USER_ID] => opsup4 [APP_ID] => Aplikasi RSS [SESSION_WKID] => [SESSION_WKIP] => 10.20.34.73 [SESSION_STARTLOGIN] => 2016-01-12 09:43:41.000 [SESSION_ENDLOGIN] => [SESSION_LOGINFLAG] => 1 [SESSION_TRXDATE] => [SESSION_CLOSEBY] => ) ) [custom_result_object] => Array ( ) [current_row] => 0 [num_rows] => [row_data] => ) Any body know why [row_data] is null although there is not null with my query result Thank's RE: Num Rows ODBC Codeigniter 3.0.3 No t Working ? - InsiteFX - 01-12-2016 NOTE: ( CodeIgniter Users Guide ) Not all database drivers have a native way of getting the total number of rows for a result set. When this is the case, all of the data is prefetched and count() is manually called on the resulting array in order to achieve the same result. RE: Num Rows ODBC Codeigniter 3.0.3 No t Working ? - mwhitney - 01-13-2016 print_r($query) is not a particularly useful method of troubleshooting a problem with your code's interaction with the database library. A given driver may not populate num_rows or row_data when you call foreach($query->result() as $row). In fact, as is evidenced in the output you posted, it's more likely that the data is stored in result_object, since calling result() with no arguments calls the result_object() method, which populates that property with the results from the driver's _fetch_object() method. The num_rows property is usually populated only after you've called the num_rows() method. If the property has previously been populated, the num_rows() method will return the value of the property, rather than attempting to either get the number from the driver or count the result_* properties. You should not be using either the num_rows property or the row_data property in your own code, as they are only intended for the database library's internal use. |