Finally I found the solution. The reason of the problem was a stupid mistake.
Shortly: using var_export
into convert a boolean value to string (false
==> "false"
) in every cycle step, and giving its each time converted return result to the db_query
function as a parameter.
Longer explained:
There is an enum field in my own MySQL table, which looks like this:
`is_own` enum('true','false')
So true
or false
values were stored as a string, this way there were only these two possible values to set. It could have also been set as 0
or 1
(or enum('0', '1')
is another possible solution), but this way I thought it will be simpler to read later, and I limited the opportunities to just two values.
To pass a boolean value to db_query()
, firstly I had to convert it to a string, so for example the false
value (as a boolean) had to be converted to "false"
(as a string), not to be casted later to 0
(because if it's casted, the update doesn't affect any rows, since for example 'false'
(as a string) isn't equal to 0
in a MySQL-query).
To do this, I used the following code snippet (using var_export):
$is_own = false;
$is_own = var_export($is_own, true);
This normally works perfectly (so it converts boolean true
to string "true"
), BUT the problem was that for some stupid reason I put this conversion in the cycle like this:
$is_own = false;
// ....
foreach($blabla as $index => $value){
// here's the mistake...!
$is_own = var_export($is_own, true);
// ....
$query_result = db_query( $query,
$value,
$prev_value,
$other_field_value,
$is_own // <--- !!
);
// ....
}
so this way $is_own
variable's value (false) was converted in every cycle step like this:
1. 'false'
2. '\'false\''
3. '\'\\\'false\\\'\''
4. '\'\\\'\\\\\\\'false\\\\\\\'\\\'\''
5. etc........
This way it's not a miracle that all of my UPDATE querys were executed successfully, but only the first resulted in some affected rows...
After some headbanging, I put my var_export
function outside the cycle (before foreach
), and now everything works perfectly. (This would be a bigger job to modify the field to INT values (0, 1), so I leave it this way.)
Anyway, thanks.