C
|
cristi 1/3/2024 |
DB::Exec expects a string but you write the query string as an query object: DB::Query("delete from commantaires where visitenr = '$id'"); There is no need for the DB::Query part because you are not returning any data - you are just deleting some records. So just delete the DB::Query part and leave the rest as: $id = $deleted_values["ID"]; Also, in my opinion, you should never leave master details delete/update relations to PHP - this is something for MySql to take care and any DB server for that matter whenever is possible. In MySQL there is something called foreign key constraints that you can use to cascade delete, update, etc child records when a primary key master value is changed or deleted - even more, using foreign keys constraints has the benefit of adding database level integrity checks for your data. In your case instead of writing PHP code you could just implement a foreign key constraint on your details table so that all the detail records will cascade delete when a master record with that ID is deleted - in my opinion this is the best solution to your problem. If you still decide to go PHP way you should parametrize your query ( using "visitenr = '$id'" is like asking for trouble). |
I
|
I author 1/3/2024 |
Thank you for the valuable tip, it works fine now |