I am learning PHP PDO with MySQL and wanted to know how to update multiple tables with one Update query linked from a single row in Table 1. Example if I wanted to update a value in table 2 and/or 3 with one query knowing only table 1 record PK id. I thought perhaps I could use Left Join, but could not get it correct. I don't need to use Left Join, just want most optimized coding.
example code that does not result in any change. I believe it is not linking correctly.
**What I desire from code: to update values in specific rows in table 2,3,ect.. by knowing only the PK from table 1 which has the foreign keys of table 2,3.
$updt = $db->prepare("UPDATE t3 LEFT JOIN t1 ON t1.table3_fk =
t3.table3_id SET t3.fooTable3=:VAR1, t3.barTable3=:VAR2 WHERE
t1.table1_id = :VARID");
$updt->bindParam(':VAR1', $VAR1, PDO::PARAM_STR);
$updt->bindParam(':VAR2', $VAR2, PDO::PARAM_STR);
$updt->bindParam(':VARID', $VARID, PDO::PARAM_STR);
$updt->execute();
Table structure:
t1 t2 t3
table1_id(PK) table2_id(PK) table3_id(PK)
table2_fk fooTable2 fooTable3
table3_fk barTable3
Example Record:
t1 t2 t3
22 10 14
10 someabcdata somedefdata
14 someefgdata
Any help would be great, thanks.
Edit1: I did try to post an image of table layout, but unfortunately I didn't have enough rep points according to this site. Thanks for the link though.
Edit2: Explained more detail
Edit3: Got rid of image for easier review