Welcome Guest, Not a member yet? Register   Sign In
Question about ORM(Update)
#1

[eluser]InterMedio[/eluser]
Hello everybody.
I wrote model t_activity.php
Code:
class T_activity extends CI_Model {

function last_act($user_id, $current) {
  $this->db->query("UPDATE sessions
        SET last_activity='$current'
        WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(user_data, '\"', 4) , '\"', -1)='$user_id'
       ");
}

}
But when I put this method into controller:
Code:
$current_ = time();
$this->t_activity->last_act($current_, $user_id);
this doesn't working.
This working, when I put this sql request in controller.
But I want store this sql query in model.
Anybody can tell me, where can be error or how correct write this request in ORM syntax?
Thanks all.
#2

[eluser]WanWizard[/eluser]
Which ORM?
#3

[eluser]InterMedio[/eluser]
It is native ORM for the CodeIgniter. So, just active record.
#4

[eluser]WanWizard[/eluser]
Codeigniter doesn't have a native ORM, it has a query builder (called active record in versions up to 2.1.0).

You need a syntax like
Code:
$this->db->where('SUBSTRING_INDEX(SUBSTRING_INDEX(user_data, '\"', 4) , '\"', -1)', $user_id, FALSE);
#5

[eluser]InterMedio[/eluser]
[quote author="WanWizard" date="1337591018"]Codeigniter doesn't have a native ORM, it has a query builder (called active record in versions up to 2.1.0).

You need a syntax like
Code:
$this->db->where('SUBSTRING_INDEX(SUBSTRING_INDEX(user_data, '\"', 4) , '\"', -1)', $user_id, FALSE);
[/quote]

Probably I mistaken and gave incorrect name to query builder. Agree.
Thank you for the advice. I'll try and describe about results.
#6

[eluser]InterMedio[/eluser]
[quote author="WanWizard" date="1337591018"]Codeigniter doesn't have a native ORM, it has a query builder (called active record in versions up to 2.1.0).

You need a syntax like
Code:
$this->db->where('SUBSTRING_INDEX(SUBSTRING_INDEX(user_data, '\"', 4) , '\"', -1)', $user_id, FALSE);
[/quote]

This query doesn't work.

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2 AND `id` = '2'' at line 1

Code:
UPDATE `users` SET `location` = 'Profile' WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(user_data, '"', 4) , '"', -1)2 AND `id` = '2'

I also used this syntax
Code:
$this->db->where("SUBSTRING_INDEX(SUBSTRING_INDEX(user_data, '\"', 4) , '\"', -1)", $user_id, FALSE);
but don't have any positive results.




Theme © iAndrew 2016 - Forum software by © MyBB