mssql_init

(PHP 4 >= 4.0.7, PHP 5, PECL odbtp >= 1.1.1)

mssql_initInicializa un stored procedure (procedimiento almacenado) local o remoto

Advertencia

Esta función está OBSOLETA en PHP 7.0.0.

Las alternativas a esta función son:

Descripción

mssql_init ( string $sp_name [, resource $link_identifier ] ) : resource

Inicializa un stored procedure (procedimiento almacenado) local o remoto.

Parámetros

sp_name

Nombre del stored procedure, como ownew.sp_name o otherdb.owner.sp_name.

link_identifier

Un identificador de la conexión MS SQL, devuelto por mssql_connect().

Valores devueltos

Devuelve un identificador de recurso llamado "statement", utilizado en subsiguientes llamadas a la función mssql_bind() y mssql_execute(), o FALSE si se producen errores.

Ejemplos

Ejemplo #1 Ejemplo de mssql_init()

<?php
// Conectar a MSSQL y seleccionar la base de datos
$link mssql_connect('KALLESPC\SQLEXPRESS''sa''phpfi');
mssql_select_db('php'$link);

// Crear una nueva sentencia
$stmt mssql_init('StatementTest'$link);

// Vincular valores aquí

// Una vez que los valores han sido vinculados ejecutamos nuestra sentencia 
// utilizando mssql_execute:
mssql_execute($stmt);

// Y liberamos el recurso del siguiente modo:
mssql_free_statement($stmt);
?>

Ver también

  • mssql_bind() - Añade un parámetro a un stored procedure (procedimiento almacenado) MSSQL (local o remoto)
  • mssql_execute() - Ejecuta un stored procedure (procedimiento almacenado) en una base de datos del servidor MS SQL
  • mssql_free_statement() - Liberar la memoria ocupada por la sentencia MS SQL

add a note add a note

User Contributed Notes 2 notes

up
1
shrockc at NOinhs dot orgSPAM
22 years ago
If you are performing a stored procedure inside a loop, it is a good idea to unset the variable that mssql_init returns so that you do NOT bind multiple values to the same stored procedure:

foreach($input  as $sid=>$value) {
  $stmt = mssql_init("sp_doSomething");
  mssql_bind($stmt, "@sid", $sid, SQLINT4, false);
  mssql_bind($stmt, "@value", $value, SQLINT4, false);
  $result = mssql_execute($stmt);
  unset($stmt);  // <---VERY important
}

Even doing the mssql_init outside the loop does not help because of the multiple binds happening inside the loop.

Failing to do the above generates "Access Violations...memory cannot be 'written'" errors on the server.  My hypothesis is that the error is generated when you try to bind to a stored procedure after it has already been executed.  You have been warned.
up
0
fjortizATcomunetDOTes
22 years ago
this function was created to support 
OUTPUT parameters and return values with
MSSQL stored procedures. Before this,
you could use T-SQL statement EXECUTE
and mssql_query to execute a stored
procedure, and it was fine as long as
you don't need to retrieve OUTPUT or
RETVAL values.


Now you can use this set of functions to execute and retrieve these values:
mssql_init
mssql_bind
mssql_execute

Parameters:
- sp_name : stored procedure name. It passes this string to a native DB-lib call, so I guess it supports all kinds of schemas (like "ownew.sp_name" or "otherdb.owner.sp_name")

- connection id: a connection resource
obtained with mssql_connect or similar.
If not provided, it will proceed just
like other similar mssql_* functions:
uses a default open connection or
creates a new one.

Return value: a resource id, called
"statement", used in subsequent calls to
mssql_bind and mssql_execute.

Note that many of the native MSSQL data types are directly supported, but I
think that some others must be converted
by other means (from varchar values for
example). These unsupported types are:

SQLMONEY4,SQLMONEY,SQLBIT,SQLDATETIM4,
SQLDATETIME, SQLDECIMAL, SQLNUMERIC,
SQLVARBINARY, SQLBINARY,SQLIMAGE

More info on supported types and new constants in mssql_bind
To Top