CodeIgniter Forums
Always Null SQL Result - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Always Null SQL Result (/showthread.php?tid=70682)



Always Null SQL Result - Refik - 05-14-2018

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?


RE: Always Null SQL Result - dave friend - 05-14-2018

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.


RE: Always Null SQL Result - InsiteFX - 05-14-2018

Try this:

Prepends a database prefix, if one exists in configuration.

PHP Code:
$this->db->dbprefix($table_name);