2-Table query
| From: | Randall Barber | Date: | Tue, 10 Apr 2001 00:31:55 +0000 |
| Subject: | 2-Table query | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-8395@lists.php.net to get a copy of this message | ||
I would like to update two tables at the same time.
Currently I update each one separately, like so,
$qryStr = "INSERT INTO table1 etc....";
odbc_exec($dbConn, $qryStr);
$qryStr = "INSERT INTO table2 etc....";
odbc_exec($dbConn, $qryStr);
Now, the problem there is if the first one passes, but the second fails, if the user tries to
re-submit, the first now fails because of a primary key clash which is right, but then never
executes the second one.
This is what I THINK I should do,
$qryStr = "(INSERT INTO table1 ( col1, col2 ) VALUES ( '$val1', '$val2' ) )
AND (INSERT INTO table2 ( col1, col2 ) VALUES ( '$val1', '$val2' ) )";
odbc_exec($dbConn, $qryStr);
Any ideas are appreciated... I am not experienced with SQL query precedences, or operators, etc...
A good reference for that very thing would be nice.
Thanks in advance,
RDB