Advertisement
virbo

Error DB handle Codeigniter 3

Dec 21st, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. ==================================
  2. = ../config/database.php
  3. ==================================
  4. $db['default'] = array(
  5.     'dsn'   => '',
  6.     'hostname' => 'localhost',
  7.     'username' => '<<USER_DB>>',
  8.     'password' => '<<PASS_DB>>',
  9.     'database' => '<<NAMA_DB>>',
  10.     'dbdriver' => 'postgre',
  11.     'dbprefix' => '',
  12.     'pconnect' => FALSE,
  13.     'db_debug' => (ENVIRONMENT !== 'production'),
  14.     'cache_on' => FALSE,
  15.     'cachedir' => '',
  16.     'char_set' => 'utf8',
  17.     'dbcollat' => 'utf8_general_ci',
  18.     'swap_pre' => '',
  19.     'encrypt' => FALSE,
  20.     'compress' => FALSE,
  21.     'stricton' => FALSE,
  22.     'failover' => array(),
  23.     'save_queries' => TRUE
  24. );
  25.  
  26. =========================================
  27. = index.php
  28. =========================================
  29. define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');
  30.  
  31. ==========================================
  32. = models untuk hapus record
  33. ==========================================
  34. function hapus($item)
  35. {
  36.         $this->db->where($this->primary_key,$item);
  37.         $this->db->delete($this->table_name);
  38. }
  39.  
  40. =========================================
  41. = controllers (fungsi delete)
  42. =========================================
  43. public function delete()
  44. {
  45.         $id = $this->input->post('id');
  46.         $this->model_name->hapus($id);
  47.        
  48.         //gunakan fungsi error untuk mengambil error yang terjadi
  49.         $error = $this->db->error();
  50.         if ($error['message']=='') {
  51.             $result = array('success'=>TRUE);
  52.             echo json_encode($result);
  53.         } else {
  54.             $result = array('errorMsg' =>$error['message']);
  55.             echo json_encode($result);
  56.         }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement