I’m having problems getting CodeIgniter to work with SQLite3.
Here are my database.php configs:
$active_group = 'sqlite';
$query_builder = TRUE;
/* SQLite3 config for PDO */
$db['sqlite'] = array (
'dsn' => 'sqlite:' .FCPATH.'virtTour_original.sqlite',
'hostname' => '',
'username' => '',
'password' => '',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
'stricton' => FALSE,
'failover' => array()
);
Here’s the controller I’m testing with:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
}
public function index()
{
$query = $this->db->get('tblBuildings');
foreach ($query->result_array() as $row)
{
echo $row;
}
}
}
/* End of file main.php */
/* Location: ./application/controllers/main.php */
This is what happens when I view main:
ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray
There are 19 rows in the table so I know it’s getting something from this (as it echos Array 19 times). But other calls do not seem to work. (i.e) echo $row['id'];
A var_dump on $query produces:
object(CI_DB_pdo_result)#16 (8) { [“conn_id”]=> object(PDO)#14 (0) { }
[“result_id”]=> object(PDOStatement)#15 (1) { [“queryString”]=>
string(28) “SELECT * FROM “tblBuildings”” } [“result_array”]=>
array(0) { } [“result_object”]=> array(0) { }
[“custom_result_object”]=> array(0) { } [“current_row”]=> int(0)
[“num_rows”]=> NULL [“row_data”]=> NULL }
There is data in the table, but it doesn’t show here…
When you are fetching the row, you get back an array, so echoing it will produce the output you see.
echo is used for primitives, for arrays you should use
print_rorvar_dump: