Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Indistinctive DB write problem
#1

[eluser]predat0r[/eluser]
I have an crud update method, which only updates the db table fields when I clear the input field (textarea) in the form, or modify the text inside. When I don't modify this field's content, so leave as is, the AR update() method doesn't run successful, the affected_rows() returns 0 / false.
I have only problem with this field.

the field has simple validation rule:

Code:
$this->form_validation->set_rules('description', 'Description', 'trim');

If I check the $_POST array after submitting the form, there are all the necessary datas, or if I check the last_query() method, the result is always the same, it has a formal correct query inside.
I have no error in mysql error log.

Of course I triple checked the typos, and it's not the first time I coded a crud, so don't have a clue..
#2

[eluser]CroNiX[/eluser]
Yes, an update really only happens when data is changed, so affected_rows() will return 0 unless data was actually updated. This is the default MySQL behavior. I believe the only way for mysql to return 1 even if no data changed is to set "CLIENT_FOUND_ROWS" in mysql.

http://stackoverflow.com/questions/14876...e-with-php
http://dev.mysql.com/doc/refman/5.0/en/i..._row-count

From Mysql (link above):
Quote:For UPDATE statements, the affected-rows value by default is the number of rows actually changed. If you specify the CLIENT_FOUND_ROWS flag to mysql_real_connect() when connecting to mysqld, the affected-rows value is the number of rows “found”; that is, matched by the WHERE clause.
#3

[eluser]predat0r[/eluser]
Thank you CroNIX, that was the problem.

So the answer for my question: mysql_affected_rows() returns 0 when the data I try to save and the data in the DB is the same, so no DB write happens in this case.




Theme © iAndrew 2016 - Forum software by © MyBB