MySql Script update on CodeIgniter [closed]
What is the
INSERT(
TGLBAYAR
, 3, 0, '/'), INSERT(TGLBAYAR
, 6, 0, '/')
Can you change it to be string? If can, on Your Model add this function and call it from controller
public function update_data(){ $fields = array( 'TGLBAYAR' => "INSERT(`TGLBAYAR`, 3, 0, '/'), INSERT(`TGLBAYAR`, 6, 0, '/')", 'TGLRUBAH' => "INSERT(`TGLRUBAH`, 3, 0, '/'), INSERT(`TGLRUBAH`, 6, 0, '/')" ); $this->db->update('Pelayanan', $fields, array()); $fields = array( 'TGLBAYAR' => array( 'name' => 'TGLBAYAR', 'type' => 'DATE', ), 'TGLRUBAH' => array( 'name' => 'TGLRUBAH', 'type' => 'DATE', ), ); $this->db->modify_column('Pelayanan', $fields); $fields = array( 'LAMA' => "DATEDIFF(`TGLBAYAR`, `TGLRUBAH`)" ); $this->db->update('Pelayanan', $fields, array()); }
the alter table section should be the followig:
$this->load->dbforge(); $fields = array( 'TGLBAYAR' => array( 'name' => 'TGLBAYAR', 'type' => 'DATE', ), 'TGLRUBAH' => array( 'name' => 'TGLRUBAH', 'type' => 'DATE', ), ); $this->dbforge->modify_column('Pelayanan', $fields);
Also, if you have any error message please share it with us.
Whatever your query is, just put it in the function $this->db->query and it will be executed very easily and you can understand it properly as you want. I have put a sample for your mysql query below:
$query = $this->db->query(" UPDATE `Pelayanan` SET `TGLBAYAR` = INSERT(`TGLBAYAR`, 3, 0, '/'), INSERT(`TGLBAYAR`, 6, 0, '/')UPDATE `Pelayanan` SET `TGLRUBAH` = INSERT(`TGLRUBAH`, 3, 0, '/'), INSERT(`TGLRUBAH`, 6, 0, '/') ALTER TABLE `Pelayanan` MODIFY COLUMN (`TGLBAYAR` DATE, `TGLRUBAH` DATE) UPDATE `Pelayanan` SET `LAMA` = DATEDIFF(`TGLBAYAR`, `TGLRUBAH`) ");