INSERTING A SQL SERVER DATA BASE WITH PHP

0

Hi, I'm trying to make an insert to a sql server database with php. I execute the program and I get the message that it was inserted correctly but when I go to look in the database it does not insert anything and I can not find the error. This is my code:

<?php
include("conexion.php");
$sql = "INSERT INTO fed_ublextensions(MPK_EMIS_ID,MPK_RECE_ID,MPK_ID,DIN_INVOICE_AUTHORIZATION,DDA_START,DDA_END,DVC_PREFIX,
DIN_FROM,DIN_TO,DCH_IDENTIFICATION_CODE,DIN_PROVIDERID,DVC_SOFTWAREID,DVC_SOFTWARESECURITYCODE,DDE_REPERCUSSIONS,DDE_TOTALTAX,DDE_TOTALCURRENCYAMOUNT) 
VALUES ('a','1','b','2','c','3','d','4','e','5','f','6','g','7','h','8')";
// arreglo acentos 
$qry_code = utf8_decode($sql);

   // Ahora ejecutamos el INSERT en la BD         
   $recurso=sqlsrv_prepare($conn,$qry_code);
$ejecutar=sqlsrv_execute($recurso);
?>
    
asked by carlos toro 11.12.2018 в 20:49
source

1 answer

0

I propose the following code: So you could capture some error:

 $sql = "INSERT INTO 
 fed_ublextensions(MPK_EMIS_ID,MPK_RECE_ID,MPK_ID,DIN_INVOICE_AUTHORIZATION,
 DDA_START, DDA_END,DVC_PREFIX, DIN_FROM,DIN_TO,DCH_IDENTIFICATION_CODE,
 DIN_PROVIDERID,DVC_SOFTWAREID,DVC_SOFTWARESECURITYCODE,
 DDE_REPERCUSSIONS,DDE_TOTALTAX,DDE_TOTALCURRENCYAMOUNT) 
 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
// arreglo acentos 

  $params = array('a','1','b','2','c','3','d','4','e','5','f','6','g','7','h','8'); 
  utf8_converter($params);

  $stmt = sqlsrv_query($conn, $sql, $params);
 if( $stmt === false ) {
 die( print_r( sqlsrv_errors(), true));
 }
 sqlsrv_free_stmt($stmt);
 //Función para convertir a utf8
 function utf8_converter($array)
{
   array_walk_recursive($array, function(&$item, $key){
      if(!mb_detect_encoding($item, 'utf-8', true)){
            $item = utf8_encode($item);
     }
 });

 return $array;
}
    
answered by 11.12.2018 / 22:53
source