I’m trying to insert into my Oracle database. My insert command returns true (i.e. success) but nothing shows up in the database. My database admin application has no record of an INSERT every getting to the database. No CI errors are thrown or appear in the log, no PHP errors, no Oracle errors—but now rows in my table.
if (!$result) { die('could not insert login to database!'); }
I’ve vardump’ed $result to confirm that it’s boolean true, and I’m successfully doing SELECTs. Here’s the gist of my database configuration, for the curious:
No luck with that. I’m trying to execute the query with PHP but completely outside CodeIgniter, and I’m encountering similar problems. I’ve discovered that my INSERT will work if I do a commit at the end, a la:
Okay, I shouldn’t have used OCI_DEFAULT there… should be OCI_COMMIT_ON_SUCCESS to commit automatically if the execute is successful. Now to find out why CI isn’t autocommiting…
Here’s a bit more information: in my application’s normal operation, I first do a SELECT, then I do the INSERT (and the INSERT doesn’t get committed). When the INSERT is the first query that hits the DB, it gets committed and I see it in the table.
Record locking perhaps?
I oracle does do row and even field level locking. Maybe your table is being locked by the select so that the insert does not work.
I think I’ve found the culprit. If my analysis is correct, the _set_stmt_id() function in oci8_driver.php will only ever run once.
function _set_stmt_id($sql) { if ( ! is_resource($this->stmt_id)) { $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); } }
When the first query comes through, stmt_id is null, and the body of the if statement gets run, which prepares the SQL for execution. The second time a query comes through, since stmt_id is now a valid resource, the query won’t get parsed and then won’t be executed.
If I take out the “if” line (and its related curly braces), and let every query get parsed, everything seems to work fine.
(Of course, I’m new to this Oracle stuff, and the fact that I’m responsible for debugging a PHP Oracle adapter is unsettling, to say the least.)
That would be awesome jonathan, and a big help. Thanks. Feel free to contact me personally (derek.allard at ellislab.com) afterwards and I’ll move on it as I can.