0
I am mounting a shopping cart but am facing the following error I mentioned in the title. The method takes 2 parameter the $listProducts is an array as all purchase information and the $Total parameter receives $_SESSION of the total purchase amount. The First Insert works well, which is the creation of the order, then I select to retrieve the last order id to enter the order items. But when you enter if the $reg variable does not receive the value of the query and gives the following error...
sqlsrv_fetch_array(): 11 is not a Valid ss_sqlsrv_stmt Resource in
What I don’t understand is why it causes this mistake, because I don’t see any error in the code.
public function CriarVenda($listaProdutos, $Total){
// criando venda
$sql = "INSERT INTO CADPEDIDO(PED_DATA, VALORTOTAL)VALUES(?,?)";
$params = array(date('Y-m-d'), $Total);
$query = sqlsrv_query($this->con->Conecta(), $sql, $params);
//resgatar última venda
$sql = "SELECT MAX(CODIGO) FROM CADPEDIDO";
$query = sqlsrv_query($this->con->Conecta(), $sql) or die( print_r( sqlsrv_errors(), true));
$ultimavenda = 0;
if($reg = sqlsrv_fetch_array($query)){
$ultimavenda = $reg[0];
}
foreach($listaProdutos as $p){
$sql = "INSERT INTO CADITENSPEDIDO(ITEM_PEDIDO, ITEM_COD_PEDIDO,ITEM_QTD ITEM_PRECO)VALUES(?,?,?,?)";
$params = array($ultimavenda, $p->Codigo, $p->Qtd_comprado, $p->SubTotal);
$query = sqlsrv_query($this->con->Conecta(), $sql, $params);
}
}
code is int? is Identity?
– rray
both the order and item code are Identity
– Alison Paulo
Can catch the last generated Identity thus
– rray
then that’s what I’m doing SELECT MAX(CODE) FROM CADPEDIDO
– Alison Paulo