I've got the following Table:
CREATE TABLE [dbo].[TestDB] (
[col1] INT NOT NULL,
[col2] VARCHAR(50) NOT NULL
);
Now I want to add entrys:
$params=array(123,'someString');
$sql = "insert into testDB values(?,?)";
$stmt = sqlsrv_query( $conntask, $sql ,$params);
if( $stmt === false) {
echo $sql;
print_r($params);
die( print_r( sqlsrv_errors(), true) );
}
If there is an error, $stmt will be false, the message will be printed and the script terminated.
My Problem
If I want to add multiple entrys, I am sending all querys at the same time.
$params=array(123,'someString','notANumber','someOtherString');
$sql = "insert into testDB values(?,?) insert into testDB values(?,?)";
$stmt = sqlsrv_query( $conntask, $sql ,$params);
if( $stmt === false) {
echo $sql;
print_r($params);
die( print_r( sqlsrv_errors(), true) );
}
In this example, the first insert will succeed and the second one will fail because I try to put a string in an int column.
Now $stmt is not false and the query gets executed until the error occurs.
My Questions:
- How can check if the Query failed at any time?
- How can I make sure that a query is either executed whole or not at all?