"IVeR", "UID"=>"sa", "PWD"=>"ReasonMac2020"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } if($_REQUEST['type'] =='save'){ $target_dir = "files/"; $target_file = $target_dir . basename($_FILES["adjunto"]["name"]); $personal = $_REQUEST['personal']; $adjunto = $_FILES["adjunto"]["name"]; $mensaje = $_REQUEST['mensaje']; $id = $_REQUEST['idsolicitud']; $tipo = $_REQUEST['tipo']; $time = new DateTime(); $tsql = "INSERT INTO respuestaSolicitud (personal,mensaje,adjunto,tipoRespuesta,fechaHora,solicitud) VALUES(?,?,?,?,?,?)"; $stmt = sqlsrv_prepare($conn, $tsql,array(&$personal, &$mensaje, &$adjunto, &$tipo, &$time, &$id)); if( sqlsrv_execute( $stmt ) === false ) { die( print_r( sqlsrv_errors(), true)); } move_uploaded_file($_FILES["adjunto"]["tmp_name"], $target_file); $data['status'] = 'Guardado ok'; $data['result'] = ''; print json_encode($data); }elseif($_REQUEST['type'] =='get'){ $id = $_REQUEST['idsolicitud']; $tsql = "SELECT s.*, res.nombre as Tipo FROM respuestaSolicitud s INNER JOIN cat_tipoRespuesta res on res.id = s.tipoRespuesta WHERE solicitud = ".$id; $stmt = sqlsrv_query($conn, $tsql); $result = array(); do { while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){ $result[] = $row; } } while (sqlsrv_next_result($stmt)); echo json_encode($result); } sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?>