mssql_init
(PHP 4 >= 4.0.7, PHP 5, PECL odbtp >= 1.1.1)
mssql_init — Initializes a stored procedure or a remote stored procedure
This function was REMOVED in PHP 7.0.0.
Alternatives to this function include:
- Using an EXEC query issued through PDO_SQLSRV, PDO_ODBC, SQLSRV, or the unified ODBC driver.
Описание
$sp_name
[, resource $link_identifier
] )Initializes a stored procedure or a remote stored procedure.
Список параметров
-
sp_name
-
Stored procedure name, like ownew.sp_name or otherdb.owner.sp_name.
-
link_identifier
-
A MS SQL link identifier, returned by mssql_connect().
Возвращаемые значения
Returns a resource identifier "statement", used in subsequent calls to
mssql_bind() and mssql_execute(),
or FALSE
on errors.
Примеры
Пример #1 mssql_init() example
<?php
// Connect to MSSQL and select the database
$link = mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
mssql_select_db('php', $link);
// Create a new statement
$stmt = mssql_init('StatementTest', $link);
// Bind values here
// Once values are binded we execute our statement
// using mssql_execute:
mssql_execute($stmt);
// And we can free it like so:
mssql_free_statement($stmt);
?>
Смотрите также
- mssql_bind() - Adds a parameter to a stored procedure or a remote stored procedure
- mssql_execute() - Executes a stored procedure on a MS SQL server database
- mssql_free_statement() - Free statement memory
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- Microsoft SQL Server
- mssql_bind
- mssql_close
- mssql_connect
- mssql_data_seek
- mssql_execute
- mssql_fetch_array
- mssql_fetch_assoc
- mssql_fetch_batch
- mssql_fetch_field
- mssql_fetch_object
- mssql_fetch_row
- mssql_field_length
- mssql_field_name
- mssql_field_seek
- mssql_field_type
- mssql_free_result
- mssql_free_statement
- mssql_get_last_message
- mssql_guid_string
- mssql_init
- mssql_min_error_severity
- mssql_min_message_severity
- mssql_next_result
- mssql_num_fields
- mssql_num_rows
- mssql_pconnect
- mssql_query
- mssql_result
- mssql_rows_affected
- mssql_select_db
Коментарии
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
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.