1
votes

I am facing some problem regarding data insertion into an oracle database (11g) with codeigniter.

first my database.php file:

$active_group = 'default';
$active_record = TRUE;


$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'turjo';
$db['default']['password'] = '123';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$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;

then in my controller..

    $conn = oci_connect('turjo', '123', 'localhost');
    if($conn) {
        echo "connected";
    }
    else {
        echo "not";
    }

which gives me connected.

then I tried ..

    $query = $this->db->query('SELECT * FROM METERREADING_CIBL');
    $data = $query->result_array();
    print_r($data);

which gives me an array Array ( [0] => Array ( [RDGN_ID] => 1 [REB_OFF_CODE] => 01 [BILL_MONTH] => JAN [METER_NO] => 1122 [BOOK_NO] => 1122 [ACC_NO] => 1122 [CRDGN] => 1 [RDGN_FLAG] => 1 [RDGN_REF_NUM] => 1 [REC_STATUS] => 1 ) )

now I want to insert some data into the table METERREADING_CIBL

what I tried is:

    $data['REB_OFF_CODE'] = "01";
    $data['BILL_MONTH'] = "FEB";
    $data['METER_NO'] = "1122";
    $data['BOOK_NO'] = "1122";
    $data['ACC_NO'] = "1122";
    $data['CORDGN'] = 1;
    $data['RDGNFLAG'] = "1";
    $data['RDGN_REF_NUM'] = "1";
    $data['REC_STATUS'] = "1";

    $this->db->insert('METERREADING_CIBL', $data);

and another way :

$this->db->query('INSERT INTO "METERREADING_CIBL" ("REB_OFF_CODE", "BILL_MONTH", "METER_NO", "BOOK_NO", "ACC_NO", "CORDGN", "RDGNFLAG", "RDGN_REF_NUM", "REC_STATUS") VALUES ("02", "FEB", "1122", "1122", "1122", "1", "1", "1", "1")');

but in both cases I got the following error:

Database error message screenshot

2
what is the datatype of BILL_MONTH in database?? - Saty
VARCHAR2(6) this is the data type for BILL_MONTH - jishan

2 Answers

0
votes

One possible cause:

Your RGDN_ID field isn't setup to be auto-populated.

It's the equivalent of what would be to insert into a MySQL table that doesn't have AUTO_INCREMENT for its primary key and you didn't provide that ID yourself.

Ask your DBA to assist you.

Update:

You've got typos in the field names that you're trying to insert:

  • RDGNFLAG vs RDGN_FLAG
  • CORDGN vs CRDGN
0
votes

Double quotes issue. Copy your statement and run on your SQL Developer. You will find an invalid character ("")

For more information please refer this link CodeIgniter - ActiveRecords and Oracle - configuration