I am using Codeigniter 2.0.1 and Postgresql 8.1. My code uses transactions within try-catch blocks.
On a simple insert at times I get a "Fatal Error"
Fatal Error: Call to a member function row() on a non-object in <...path...>/system/database/drivers/postgre/postgre_driver.php on line 357
My Database Config is:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "***";
$db['default']['password'] = "***";
$db['default']['database'] = "***";
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
The lne of my Model code that is causing the error is "$id = $this->db->insert_id();". I say so because the line that causes the error is within insert_id() method and it is being used only once in the model. A code snapshot of the model is given below.
try {
// CODE TO FILL UP $data ARRAY
$this->DBquery("BEGIN");
$this->DBinsert('<TABLE NAME>', $data);
$id = $this->db->insert_id();
// SOME MORE CODE
}
catch(Exception $e) {
$this->DBquery("ROLLBACK");
//echo $e->getMessage();
return 0;
}
$this->DBquery("COMMIT");
return $id;
$this->DBquery and $this->DBinsert are custom methods made by me on a base model class which extends the CI_Model class. These methods function full well.
Below is the insert_id method in postgre_driver.php and line 357 is "$row = $query->row();"
function insert_id()
{
$v = $this->_version();
$v = $v['server'];
$table = func_num_args() > 0 ? func_get_arg(0) : NULL;
$column = func_num_args() > 1 ? func_get_arg(1) : NULL;
if ($table == NULL && $v >= '8.1')
{
$sql='SELECT LASTVAL() as ins_id';
}
elseif ($table != NULL && $column != NULL && $v >= '8.0')
{
$sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
$query = $this->query($sql);
$row = $query->row();
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
}
elseif ($table != NULL)
{
// seq_name passed in table parameter
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
}
else
{
return pg_last_oid($this->result_id);
}
$query = $this->query($sql);
$row = $query->row(); // LINE 357
return $row->ins_id;
}
Its so more confusing because the problem is not always. It happens sometimes but with a good enough frequency to hamper work. The system is being used by about 8-10 users and so I guess concurrency should not be an issue. Also, I am using pconnect and number of connections is unlimited.