I have a function called cargar combo:
function cargarcombo($VALOR,$DESCRIPCION,$TABLA, $CONDICION, $VALORACTUAL)
{
$serverName = "IP\BD";
$connectionInfo = array( "Database"=> 'Coop' );
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT $VALOR ,$DESCRIPCION FROM $TABLA $CONDICION";
echo $sql;
global $conn;
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
if ($VALORACTUAL == $row[$VALOR]){
$select = ' Selected ';
}
else {
$select = '';
}
echo "<option value=\"" . $row[$VALOR] . "\" $select> " . $row[$DESCRIPCION] . " </option>";
echo "\n";
}
sqlsrv_free_stmt( $stmt);
}
called from my div :
<div class="col-sm-10">
<select class="form-control" name="producto" id="producto">
<option value="">[Generico]</option>
<?php cargarcombo('ARTICULO', 'DESCRIPCION' , 'Cooperativa.dbo.articulos', ' order by DESCRIPCION asc ', $cbousuario); ?>
</select>
</div>
and throws this error:
sqlsrv_query() expects parameter 1 to be resource, null given in Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] => An invalid parameter was passed to sqlsrv_query. [message] => An invalid parameter was passed to sqlsrv_query. ) )
Anyone has an idea? because my conexion is OK, idk why it says is a null and not a resource?