PHP - PHP SQLSERVER Procedimiento almacenado

 
Vista:
sin imagen de perfil

PHP SQLSERVER Procedimiento almacenado

Publicado por agu (6 intervenciones) el 17/08/2016 05:14:43
hola necesito ejecutar un procedimiento almacenado en una base de datos SQL Server, este procedimiento es un procedimiento de insercion de datos el cual recibe datos enviados desde php. Este es el codigo que utilizo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
<head>
</head>
<body>
<form method="post" action="Altaempresa.php" >
 
 
Razon Social:<br>
<input type="text" name="razonsocial" /> <br>
CUIT:<br>
<input type="text" name="cuit" /> <br>
Direccion:<br>
<input type="text" name="direccion" /> <br>
Piso:<br>
<input type="text" name="piso" /> <br>
 
Numero de departamento:<br>
<input type="text" name="numerodepartamento" /> <br>
 
Email:<br>
<input type="text" name="mail" ><br><br>
 
<input type="submit" value="Ingreso" name="Ingresar" />
 
</form>
</body>
</html>
 
 
<?php
 
 
	$server = 'USUARIO-PC\AGU';
	$connectionInfo = array("Database"=>"GESTION-IMT", "UID"=>"sa", "PWD"=>"123");
	$conexion = sqlsrv_connect($server, $connectionInfo);
 
    if( $conexion )
    {
     echo "Conexión establecida.<br />";
 
	 if (isset($_POST["Ingresar"]))
	 {
 
		$razonsocial = $_POST['razonsocial'];
		$cuit = $_POST['cuit'];
		$direccion = $_POST['direccion'];
		$piso = $_POST['piso'];
		$numerodepartamento = $_POST['numerodepartamento'];
		$mail= $_POST['mail'];
 
		$sql = "{CALL AltaEmpresa values(?, ?, ?, ?, ?, ?)}";
		$params =  array(
		array($razonsocial, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(50)),
		array($cuit, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(11)),
		array($direccion, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(50)),
		array($piso, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT),
                array($numerodepartamento, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(4)),
                array($mail, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(50))
		);
 
		$stmt = sqlsrv_query($conexion, $sql, $params);  //en esta linea esta el problema='/img/emoticons/angry.gif' width='22' height='22' border='0' />='/img/emoticons/angry.gif' width='22' height='22' border='0' />
 
		if($stmt === false)
        {
			echo "Algo salio mal";
			die(print_r(sqlsrv_errors(), true));
		}
 
     }
	}
	else
    {
		echo "Conexión no se pudo establecer.<br />";
		die( print_r( sqlsrv_errors(), true));
	}
 
?>

este es el error que me aparece:

Fatal error: core_sqlsrv_bind_param: invalid encoding in C:\xampp\htdocs\proyecto\Altaempresa.php on line 61

muchas gracias por su ayuda
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de kip
Val: 2.325
Plata
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

PHP SQLSERVER Procedimiento almacenado

Publicado por kip (877 intervenciones) el 17/08/2016 05:31:16
Hola, haz probado colocando los valores a ingresar en el array sin especificacion de los tipos de datos que ingresaras y que retornara? Te lo pregunto porque el mensaje te dice que la codificacion es invalida y de seguro se debe a aquel ENC_CHAR que haces en el tipo de dato a retornar.

En el manual especifican que estructurar de esa forma los parametros es opcional, lo principal es el valor a ingresar.

Aunque de todas formas aqui te dejo un enlace que de seguro te ayudara:
https://msdn.microsoft.com/en-us/library/cc296208.aspx

Nos cuentas si lo solucionas!

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar