I am trying to automatically update a field containing username of the user who most recently modified a record. To do this, I want to use an update-after hook.
[pre]
$hooks['sample_log']['update']['after'] = 'dadabik_update_username_sample_log';
function dadabik_update_username_sample_log($id)
{
global $conn;
$sql = "UPDATE sample_log SET updated_by = ".$quote.$current_user.$quote." WHERE id = :id";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':id', $id);
$res = execute_prepared_db($res_prepare,0);
}
[/pre]
When tested with on sample_log.id = 3, The hook elicits the following error: [08] Error: during query execution. The DBMS server said: SQLSTATE[42000]: Syntax error or access violation: 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 'WHERE id = '3'' at line 1.
As far as I can tell, the sql parses correctly, so I'm not sure where I'm going wrong. I expect it is something really simple, but the solution has bedeviled me.
----
DaDaBIK version 9.2-Monterosso enterprise, installed on 12-31-2018 (installation code: 142345c29be87db0ca), the latest version of DaDaBIK is 9.4-Monterosso released on 07-23-2019
PHP Version: 7.2.19-0ubuntu0.18.04.2
mysql version: 5.7.27-0ubuntu0.18.04.1
Web server: Apache/2.4.29 (Ubuntu)
Client: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36
[pre]
$hooks['sample_log']['update']['after'] = 'dadabik_update_username_sample_log';
function dadabik_update_username_sample_log($id)
{
global $conn;
$sql = "UPDATE sample_log SET updated_by = ".$quote.$current_user.$quote." WHERE id = :id";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':id', $id);
$res = execute_prepared_db($res_prepare,0);
}
[/pre]
When tested with on sample_log.id = 3, The hook elicits the following error: [08] Error: during query execution. The DBMS server said: SQLSTATE[42000]: Syntax error or access violation: 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 'WHERE id = '3'' at line 1.
As far as I can tell, the sql parses correctly, so I'm not sure where I'm going wrong. I expect it is something really simple, but the solution has bedeviled me.
----
DaDaBIK version 9.2-Monterosso enterprise, installed on 12-31-2018 (installation code: 142345c29be87db0ca), the latest version of DaDaBIK is 9.4-Monterosso released on 07-23-2019
PHP Version: 7.2.19-0ubuntu0.18.04.2
mysql version: 5.7.27-0ubuntu0.18.04.1
Web server: Apache/2.4.29 (Ubuntu)
Client: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36