php - Select after insert doesn't return the inserted row -
background information: work on application (professional, not personal) manage files. ui web based , low-level file managing functions java based.
each file , directory referred 'node' in app , has row in table store inode, name, parent id, etc...
the problem: when action adding node or renaming example, java function called update database in relation real file system.
i have problem when copy node (everything works when add, rename, delete, ... node if same exact java function called copy) ==> file copied, java function called (in case sql insert of new file infos) , select in php node id of copied file.
just after insert can see row in phpmyadmin select in php doesn't return it.
what i've tried: it's not timing (i've put 20 seconds sleep test , have time see row in pma) , caches disabled in codeigniter (and i've put various dumps in codeigniter code confirm). tried pdo driver of codeigniter , result same. , i've tried delete of conditions in clause (and clause altogether too) , again, same result.
the thing works open new connection db , redo query in code below:
public function getidfornode($name, $parentid) { $id = 0; $name = self::cleanname($name); $parentid = intval($parentid); if (empty($name)) { log::error("\$name can't empty."); } else if ($parentid < 0) { log::error("\$parentid can't < 0."); } else { $db = appdatabase::getinstance(); $sql = "select node_id nodes inode_id > 0 , parentnode_id = ? , record_label = binary ? , record_deleted null"; $result = $db->query($sql, [$parentid, $name])->row_array(); /////////////////////////////////////////////////////////////////// if (empty($result)) { $db2 = new mysqli(db_host, db_user, db_pass, db_name); $result2 = $db2->query(" select node_id nodes inode_id > 0 , parentnode_id = ".$parentid." , record_label = binary '".$db2->escape_string($name)."' , record_deleted null "); $result = $result2->fetch_assoc(); $result2->free(); $db2->close(); } /////////////////////////////////////////////////////////////////// $id = (!empty($result) && !empty($result['node_id'])) ? intval($result['node_id']) : 0; } return $id; }
mysql 5.5
php 5.5
codeigniter 3
please let me know if need other info.
Comments
Post a Comment