I need to run an insert and a simultaneous update, but I’m using only insert test to catch errors.
The PDO does not report the error when I define a correct and an incorrect table, but if I run a query to select one incorrect table the error is reported.
I do not have enough knowledge to solve this problem, i really need to execute two queries together
Thank you.
$db-> setAttribute( PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION );
try{
$stmt = $db-> prepare( "INSERT INTO test ( name ) values( 'new name' );
INSERT INTO xast ( xame ) values( 'new name' );" );
$stmt->execute();
}catch( PDOException $e ){
print_r( $e );
}
try{
$stmt = $db-> prepare( "INSERT INTO xast ( xame ) values( 'new name' );" );
$stmt->execute();
}catch( PDOException $e ){
print_r( $e );
}
**Column not found: 1054 Unknown column 'xame'**
there is no point in preparing multiple queries in your case.
First, prepared statements invented especially for tins case: prepare once, execute many. So, you can prepare this way
and then execute as many times as many inserts you have
Next. For the INSERT query Mysql supports multiple VALUES clause in one query, like
and so on.
If you need to update after insert – no problem too.
Just run 2 separate queries – one INSERT and one UPDATE. There will be not a single problem.