db = \Config\Database::connect($this->con_name); log_message('critical', "BaseModel-Entered" ); } public function insert_db($inserDataArray, $insertTable) { log_message('critical', "insert_db-WAS CALLED user 000=>" ); $insert_id=0; $ic = 0; $fl_part = ''; $val_part = ''; $sqlQ = ''; // try { $fields = array_keys($inserDataArray); log_message('critical', "insert_db-WAS CALLED user 009a=>" ); foreach ($fields as $field) { $fl_part .= $ic > 0 ? ',' : ''; $fl_part .= $field; $val_part .= $ic > 0 ? ',' : ''; $val_part .= "'" . $inserDataArray[$field] . "'"; $ic++; } log_message('critical', "insert_db-WAS CALLED user 009b=>" ); $sqlQ = "INSERT INTO $insertTable ($fl_part) VALUES ($val_part)"; log_message('critical', "SQL-WAS CALLED user =>". $sqlQ ); $query = $this->db->query($sqlQ); if(!$query){ $insert_id=-1; } // $insert_id = $this->db->insert_id(); // $insert_id = $this->db->getInsertID(); // $this->db->insert($insertTable,$inserDataArray); // $insert_id = $this->db->insert_id(); // } catch (Exception $e) { //echo 'Caught exception: ', $e->getMessage(), "\n"; // log_message('critical', "Caught exception: => ".$e->getMessage() ); // } return $insert_id; } public function update_db($UupdateDataArray,$whereAray, $updateTable) { $ic = 0; $UP_part = ''; $val_part = ''; $sqlQ = ''; $fields = array_keys($UupdateDataArray); foreach ($fields as $field) { $UP_part .= $ic > 0 ? ',' : ''; $UP_part .= $field="'" . $UupdateDataArray[$field] . "'"; $ic++; } $ic = 0; $fields = array_keys($whereAray); foreach ($fields as $field) { $val_part .= $ic > 0 ? ' AND ' : ' WHERE '; $val_part .= $field."='" . $whereAray[$field] . "'"; $ic++; } $sqlQ = "UPDATE $updateTable SET $UP_part $val_part"; $query = $this->db->query($sqlQ); return 0; } public function getIPAddress() { //whether ip is from the share internet if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } //whether ip is from the proxy elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } //whether ip is from the remote address else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } }