Welcome Guest, Not a member yet? Register   Sign In
$this->db->affected_rows()
#3

[eluser]Michael;[/eluser]
[quote author="Derek Allard" date="1205996391"]Hey Dixen. Let's work through this.

Could you start by simplifying this example down to the very minimum needed to recreate your error? If you take it out of a model and do it directly in a controller do you experience this? If you don't harvest data for insert, but instead use hard-coded values to you experience this? I want to figure out exactly where this is happening in the most simple example we can get.
[/quote]

Before you run affected rows, what happens if you output $this->db->last_query() to the screen. Does it give you what you expect?

Quote:Is there a reason you're directly reading POST and SESSION vars instead of using $this->input->post("foo") or counterparts?

Honestly, because I'm relatively new to CI and I'm not fully familiar with all it's pieces parts yet. Although, I am using native php sessions because of the limitation of 4kb on CI sessions.

Quote:Before you run affected rows, what happens if you output $this->db->last_query() to the screen. Does it give you what you expect?

Yes:

Code:
INSERT INTO forum_topics (board_id, user_id, topic, dt_create, dt_update) VALUES ('1', '1', 'test', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())

Quote:Could you start by simplifying this example down to the very minimum needed to recreate your error? If you take it out of a model and do it directly in a controller do you experience this? If you don't harvest data for insert, but instead use hard-coded values to you experience this?

This code, still produces no result; which is stripped down as it can get. The query *IS* working as I can view the resulting record that is inserted into the database.

Code:
function add_topic($_POST) {
      $topic_add = $this->db->query("INSERT INTO forum_topics (board_id, user_id, topic, dt_create, dt_update) VALUES ('".$this->dot_common->dbsafe($_POST['board_id'])."', '".$this->dot_common->dbsafe($_SESSION['uid'])."', '".$this->dot_common->dbsafe(trim(htmlspecialchars($_POST['topic'])))."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())");
      return $this->db->affected_rows;
    }

If I do the following:

Code:
function add_topic($_POST) {
      $topic_add = $this->db->query("INSERT INTO forum_topics (board_id, user_id, topic, dt_create, dt_update) VALUES ('".$this->dot_common->dbsafe($_POST['board_id'])."', '".$this->dot_common->dbsafe($_SESSION['uid'])."', '".$this->dot_common->dbsafe(trim(htmlspecialchars($_POST['topic'])))."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())");
      $topic_id = $this->db->insert_id();
      return $topic_id;
    }

I can print topic_id going into the function, both in the controller, and in the model... and coming out of the model correctly. ONLY affected rows is not producing a result.

And lastly, if I put the following:

Code:
$topic_add = $this->db->query("INSERT INTO forum_topics (board_id, user_id, topic, dt_create, dt_update) VALUES ('".$this->dot_common->dbsafe($_POST['board_id'])."', '".$this->dot_common->dbsafe($_SESSION['uid'])."', '".$this->dot_common->dbsafe(trim(htmlspecialchars($_POST['topic'])))."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())");
      $num = $this->db->affected_rows;
      print $num;


Messages In This Thread
$this->db->affected_rows() - by El Forum - 03-19-2008, 07:33 PM
$this->db->affected_rows() - by El Forum - 03-19-2008, 07:59 PM
$this->db->affected_rows() - by El Forum - 03-19-2008, 08:35 PM
$this->db->affected_rows() - by El Forum - 03-19-2008, 08:41 PM
$this->db->affected_rows() - by El Forum - 03-19-2008, 08:43 PM
$this->db->affected_rows() - by El Forum - 03-19-2008, 08:46 PM
$this->db->affected_rows() - by El Forum - 03-19-2008, 08:58 PM
$this->db->affected_rows() - by El Forum - 03-21-2008, 07:22 PM
$this->db->affected_rows() - by El Forum - 03-21-2008, 09:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB