-
Harry05
Newbie
-
Posts: 2
Threads: 1
Joined: Sep 2015
Reputation:
0
Aloha,
I have a sql query looks like this 1:1 test query this is it how I have to used it.
Code: insert into files (created,name,timestamp)values (now(),'xxxx', '2015-08-26 00:00:00')
ON DUPLICATE KEY UPDATE created=NOW(),status='NEW';
and I like have it so ,for exampel.
PHP Code: public function get_select_file() { $this->db->select ( 'id' ); $this->db->from ( 'table' ); $this->db->where ( 'name', 'xxxx' ); $this->db->where ( 'timestamp', '2015-08-26 00:00:00' ); $query = $this->db->get (); return $query->result_array (); }
or some thing like this pleas help my !!
-
rtorralba
Junior Member
-
Posts: 46
Threads: 4
Joined: Oct 2014
Reputation:
5
09-04-2015, 11:20 AM
(This post was last modified: 09-04-2015, 11:23 AM by rtorralba.)
(09-04-2015, 10:05 AM)Harry05 Wrote: Aloha,
I have a sql query looks like this 1:1 test query this is it how I have to used it.
Code: insert into files (created,name,timestamp)values (now(),'xxxx', '2015-08-26 00:00:00')
ON DUPLICATE KEY UPDATE created=NOW(),status='NEW';
and I like have it so ,for exampel.
PHP Code: public function get_select_file() { $this->db->select ( 'id' ); $this->db->from ( 'table' ); $this->db->where ( 'name', 'xxxx' ); $this->db->where ( 'timestamp', '2015-08-26 00:00:00' ); $query = $this->db->get (); return $query->result_array (); }
or some thing like this pleas help my !!
I think that you want execute the first query with codeigniter query builder (like second code). If you want to do this there isn't on duplicate key update sentence at codeigniter query builder. But you can execute it as following way:
PHP Code: public function insert($name, $timestamp) { $sql = "insert into files (created,name,timestamp)values (now(),'$name', '$timestamp') ON DUPLICATE KEY UPDATE created=NOW(),status='NEW';"; return $this->db->query($sql); }
But viewing your query my question is, I supose you use on duplicate key sentence for skip possible concurrence because your primary key is "created", why you don't use autoincrement int for primary key? then your sentence whould be like following:
Code: insert into files (created,name,timestamp)values (now(), 'xxxx', '2015-08-26 00:00:00')
And with ci query builder:
PHP Code: public function insert($name, $timestamp) { $data = array('name' => $name, 'timestamp' => $timestamp); return $this->db->insert('files' $data); }
Greetings.
-
Harry05
Newbie
-
Posts: 2
Threads: 1
Joined: Sep 2015
Reputation:
0
(09-04-2015, 11:20 AM)rtorralba Wrote: (09-04-2015, 10:05 AM)Harry05 Wrote: Aloha,
I have a sql query looks like this 1:1 test query this is it how I have to used it.
Code: insert into files (created,name,timestamp)values (now(),'xxxx', '2015-08-26 00:00:00')
ON DUPLICATE KEY UPDATE created=NOW(),status='NEW';
and I like have it so ,for exampel.
PHP Code: public function get_select_file() { $this->db->select ( 'id' ); $this->db->from ( 'table' ); $this->db->where ( 'name', 'xxxx' ); $this->db->where ( 'timestamp', '2015-08-26 00:00:00' ); $query = $this->db->get (); return $query->result_array (); }
or some thing like this pleas help my !!
I think that you want execute the first query with codeigniter query builder (like second code). If you want to do this there isn't on duplicate key update sentence at codeigniter query builder. But you can execute it as following way:
PHP Code: public function insert($name, $timestamp) { $sql = "insert into files (created,name,timestamp)values (now(),'$name', '$timestamp') ON DUPLICATE KEY UPDATE created=NOW(),status='NEW';"; return $this->db->query($sql); }
But viewing your query my question is, I supose you use on duplicate key sentence for skip possible concurrence because your primary key is "created", why you don't use autoincrement int for primary key? then your sentence whould be like following:
Code: insert into files (created,name,timestamp)values (now(), 'xxxx', '2015-08-26 00:00:00')
And with ci query builder:
PHP Code: public function insert($name, $timestamp) { $data = array('name' => $name, 'timestamp' => $timestamp); return $this->db->insert('files' $data); }
because I have filetable file id = autoincrement the other table called data I insert in this table data with the same key from file table
|