I'm trying to update a field using the Drupal's bootstrapped db_update or db_query library functions for PHP. However, neither of them are working. IF I RUN THE QUERYS MANUALLY, THEY WORK.
These two queries are the exact same. They are equivalent to doing
update field_data_field_department set delta = 4 where entity_id = 10568 and delta = 0;
Please tell me what I need to do to execute this query from PHP and make it work.
db_query("update field_data_field_department set delta = $highest_delta where entity_id = $entityID and delta = $i");
OR
$num_affected = db_update('field_data_field_department')
->fields(array(
'delta' => $highest_delta
))
->condition('entity_id', $entityID)
->condition('delta', $i)
->execute();
echo "num_affected: $num_affected\n";
num_affected returns 1 every time.
Here is the state of the database before the query is executed.
MariaDB [db]> explain field_data_field_department;
+----------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+------------------+------+-----+---------+-------+
| entity_type | varchar(128) | NO | PRI | | |
| bundle | varchar(128) | NO | MUL | | |
| deleted | tinyint(4) | NO | PRI | 0 | |
| entity_id | int(10) unsigned | NO | PRI | NULL | |
| revision_id | int(10) unsigned | YES | MUL | NULL | |
| language | varchar(32) | NO | PRI | | |
| delta | int(10) unsigned | NO | PRI | NULL | |
| field_department_tid | int(10) unsigned | YES | MUL | NULL | |
+----------------------+------------------+------+-----+---------+-------+
8 rows in set (0.08 sec)
MariaDB [db]> select * from field_data_field_department where entity_id = 10568;
+-------------+--------+---------+-----------+-------------+----------+-------+----------------------+
| entity_type | bundle | deleted | entity_id | revision_id | language | delta | field_department_tid |
+-------------+--------+---------+-----------+-------------+----------+-------+----------------------+
| node | person | 0 | 10568 | 25093 | und | 0 | 39 |
| node | person | 0 | 10568 | 25093 | und | 1 | 30 |
| node | person | 0 | 10568 | 25093 | und | 2 | 41 |
| node | person | 0 | 10568 | 25093 | und | 3 | 38 |
+-------------+--------+---------+-----------+-------------+----------+-------+----------------------+
4 rows in set (0.00 sec)