• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Always Null SQL Result

#1
Hi ı have a problem with PDO 

My db config : 
Code:
$db['default'] = array(
    'dsn'    => 'mysql:host=localhost;dbname=ebaskan1_codeigniter',
    'hostname' => 'localhost',
    'username' => 'ebaskan1_codeigniter',
    'password' => 'xxx',
    'database' => 'ebaskan1_codeigniter',
    'dbdriver' => 'pdo',
    'dbprefix' => 'ren_',
    'pconnect' => FALSE,
    '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
);

My SQL Code:
Code:
$this->db->get('users'); or $this->db->query("SELECT * FROM ren_users");

var_dump results:
Code:
object(CI_DB_pdo_result)#20 (8) {
 ["conn_id"]=>
 object(PDO)#14 (0) {
 }
 ["result_id"]=>
 object(PDOStatement)#19 (1) {
   ["queryString"]=>
   string(23) "SELECT * FROM ren_users"
 }
 ["result_array"]=>
 array(0) {
 }
 ["result_object"]=>
 array(0) {
 }
 ["custom_result_object"]=>
 array(0) {
 }
 ["current_row"]=>
 int(0)
 ["num_rows"]=>
 NULL
 ["row_data"]=>
 NULL
}

Yes my sql connections is true and yes again ı'am search this in google but ı cant fix. How can ı take the data from database. How can ı fix this?
Reply

#2
After calling get() or query() you need to use the returned object to Generate Query Results.

Something along these lines

PHP Code:
$query $this->db->get('users');
$data $query->result();
var_dump($data); 

The dump should show an array where each "row" from the table is a stdClass object.
The link to the documentation provided above details what to expect and shows the other "results" methods available.
Reply

#3
Try this:

Prepends a database prefix, if one exists in configuration.

PHP Code:
$this->db->dbprefix($table_name); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.