Welcome Guest, Not a member yet? Register   Sign In
Postgres, multiple databases, no result?
#1

[eluser]3rdear[/eluser]
Hi,

I have what appears to be a rather odd problem. All database connections and queries are correct, but I'm not actually get result data. Please see below:

Code:
public function getEntities($entityManager)
  {
    
    // $entityManager string which determines which database to connect to

    $emdb=$this->load->database($entityManager,TRUE);
    $sql="SELECT * FROM tblmarketsource";
    $entities=$emdb->query($sql);  
    $this->setEntities($entities);
    
      
  }

Now, if we do a var_dump() on $emdb, we get the following, which looks like a perfectly valid database connection ... and it IS:

Code:
object(CI_DB_postgre_driver)#20 (71) {
  ["dbdriver"]=>
  string(7) "postgre"
  ["_escape_char"]=>
  string(1) """
  ["_like_escape_str"]=>
  string(13) " ESCAPE '%s' "
  ["_like_escape_chr"]=>
  string(1) "!"
  ["_count_string"]=>
  string(19) "SELECT COUNT(*) AS "
  ["_random_keyword"]=>
  string(9) " RANDOM()"
  ["ar_select"]=>
  array(0) {
  }
  ["ar_distinct"]=>
  bool(false)
  ["ar_from"]=>
  array(0) {
  }
  ["ar_join"]=>
  array(0) {
  }
  ["ar_where"]=>
  array(0) {
  }
  ["ar_like"]=>
  array(0) {
  }
  ["ar_groupby"]=>
  array(0) {
  }
  ["ar_having"]=>
  array(0) {
  }
  ["ar_keys"]=>
  array(0) {
  }
  ["ar_limit"]=>
  bool(false)
  ["ar_offset"]=>
  bool(false)
  ["ar_order"]=>
  bool(false)
  ["ar_orderby"]=>
  array(0) {
  }
  ["ar_set"]=>
  array(0) {
  }
  ["ar_wherein"]=>
  array(0) {
  }
  ["ar_aliased_tables"]=>
  array(0) {
  }
  ["ar_store_array"]=>
  array(0) {
  }
  ["ar_caching"]=>
  bool(false)
  ["ar_cache_exists"]=>
  array(0) {
  }
  ["ar_cache_select"]=>
  array(0) {
  }
  ["ar_cache_from"]=>
  array(0) {
  }
  ["ar_cache_join"]=>
  array(0) {
  }
  ["ar_cache_where"]=>
  array(0) {
  }
  ["ar_cache_like"]=>
  array(0) {
  }
  ["ar_cache_groupby"]=>
  array(0) {
  }
  ["ar_cache_having"]=>
  array(0) {
  }
  ["ar_cache_orderby"]=>
  array(0) {
  }
  ["ar_cache_set"]=>
  array(0) {
  }
  ["ar_no_escape"]=>
  array(0) {
  }
  ["ar_cache_no_escape"]=>
  array(0) {
  }
  ["username"]=>
  string(8) "MY_USERNAME"
  ["password"]=>
  string(7) "MY_PASSWORD"
  ["hostname"]=>
  string(8) "MY_SERVER"
  ["database"]=>
  string(29) "MY_DATABASE"
  ["dbprefix"]=>
  string(0) ""
  ["char_set"]=>
  string(4) "utf8"
  ["dbcollat"]=>
  string(15) "utf8_general_ci"
  ["autoinit"]=>
  bool(true)
  ["swap_pre"]=>
  string(0) ""
  ["port"]=>
  string(0) ""
  ["pconnect"]=>
  bool(true)
  ["conn_id"]=>
  resource(20) of type (pgsql link persistent)
  ["result_id"]=>
  bool(false)
  ["db_debug"]=>
  bool(true)
  ["benchmark"]=>
  int(0)
  ["query_count"]=>
  int(0)
  ["bind_marker"]=>
  string(1) "?"
  ["save_queries"]=>
  bool(true)
  ["queries"]=>
  array(0) {
  }
  ["query_times"]=>
  array(0) {
  }
  ["data_cache"]=>
  array(0) {
  }
  ["trans_enabled"]=>
  bool(true)
  ["trans_strict"]=>
  bool(true)
  ["_trans_depth"]=>
  int(0)
  ["_trans_status"]=>
  bool(true)
  ["cache_on"]=>
  bool(false)
  ["cachedir"]=>
  string(0) ""
  ["cache_autodel"]=>
  bool(false)
  ["CACHE"]=>
  NULL
  ["_protect_identifiers"]=>
  bool(true)
  ["_reserved_identifiers"]=>
  array(1) {
    [0]=>
    string(1) "*"
  }
  ["stmt_id"]=>
  NULL
  ["curs_id"]=>
  NULL
  ["limit_used"]=>
  NULL
  ["stricton"]=>
  bool(false)
}

Continuing on, if we do a var_dump() on $entities, that is where the weirdness begins ...

Code:
object(CI_DB_postgre_result)#22 (8) {
  ["conn_id"]=>
  resource(20) of type (pgsql link persistent)
  ["result_id"]=>
  resource(21) of type (pgsql result)
  ["result_array"]=>
  array(0) {
  }
  ["result_object"]=>
  array(0) {
  }
  ["custom_result_object"]=>
  array(0) {
  }
  ["current_row"]=>
  int(0)
  ["num_rows"]=>
  int(27)
  ["row_data"]=>
  NULL
}

Notice how the element "num_rows" = 27 but there appears to be no "result object", no "custom_result_object" and no "row_data". Incidentally, in the above case, the actual query if run in pgAdmin does return 27 rows full of data, but CI doesn't return squat. Also, if we do a var_dump on $entities->num_fields() we actually get an integer of 5, which is also correct. So why would ALL the "result" elements be empty and why would "row_data" be NULL? Please help me out here.





Theme © iAndrew 2016 - Forum software by © MyBB