PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mssql_close> <Mssql Functions
Last updated: Fri, 22 Aug 2008

view this page in

mssql_bind

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

mssql_bindAdds a parameter to a stored procedure or a remote stored procedure

Descripción

bool mssql_bind ( resource $stmt , string $param_name , mixed &$var , int $type [, int $is_output [, int $is_null [, int $maxlen ]]] )

Binds a parameter to a stored procedure or a remote stored procedure.

Lista de parámetros

stmt

Statement resource, obtained with mssql_init().

param_name

The parameter name, as a string.

Note: You have to include the @ character, like in the T-SQL syntax. See the explanation included in mssql_execute().

var

The PHP variable you'll bind the MSSQL parameter to. You can pass it by value, or by reference, to retrieve OUTPUT and RETVAL values after the procedure execution.

type

One of: SQLTEXT, SQLVARCHAR, SQLCHAR, SQLINT1, SQLINT2, SQLINT4, SQLBIT, SQLFLT4, SQLFLT8, SQLFLTN.

is_output

Whether the value is an OUTPUT parameter or not. If it's an OUTPUT parameter and you don't mention it, it will be treated as a normal input parameter and no error will be thrown.

is_null

Whether the parameter is NULL or not. Passing the NULL value as var will not do the job.

maxlen

Used with char/varchar values. You have to indicate the length of the data so if the parameter is a varchar(50), the type must be SQLVARCHAR and this value 50.

Valores retornados

Devuelve TRUE si todo se llevó a cabo correctamente, FALSE en caso de fallo.

Ejemplos

Example #1 mssql_bind() Example

<?php

$cn 
mssql_connect($DBSERVER$DBUSER$DBPASS);
mssql_select_db($DB$cn);

$sp mssql_init("WDumpAdd"); // stored proc name

mssql_bind($sp"@productname"stripslashes($newproduct), SQLVARCHARfalsefalse150);
mssql_bind($sp"@quantity"stripslashes($newquantity), SQLVARCHARfalsefalse50);

mssql_execute($sp);
mssql_close($cn);

?>



mssql_close> <Mssql Functions
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
mssql_bind
Anonymous
08-Jun-2008 07:52
for type :

SQLCHAR     DBCHAR
SQLVARCHAR     DBCHAR
SQLTEXT     DBCHAR
SQLBINARY     DBBINARY
SQLVARBINARY     DBBINARY
SQLIMAGE     DBBINARY
SQLINT1     DBTINYINT
SQLINT2     DBSMALLINT
SQLINT4     DBINT
SQLFLT4     DBFLT4
SQLFLT8     DBFLT8
SQLBIT     DBBIT
SQLMONEY4     DBMONEY4
SQLMONEY     DBMONEY
SQLDATETIM4     DBDATETIM4
SQLDATETIME     DBDATETIME
SQLDECIMAL     DBDECIMAL
SQLNUMERIC     DBNUMERIC

source : http://msdn.microsoft.com/en-us/library/aa937008(SQL.80).aspx
daryl dot mitchell at usask dot ca
05-Dec-2007 06:56
I had the same problem but the posted solution above just produced null results.  Here's a modification that ended up working:

#THIS SUCCEEDS, USES A REFERENCE
mssql_bind($proc, '@'.$key, $sp_parms[$key], SQLVARCHAR)
or die("Unable to bind $sp_name:$key<br>".mssql_get_last_message());
fheald at buzztime dot com
06-Aug-2007 09:27
mssql_bind binds by reference, not by value, even on input parameters.  Improper binding can cause strange errors; in my case "Error converting data type varchar to int"

--SAMPLE STORED PROCEDURE
CREATE Procedure [dbo].[myproc]
(
    @one VARCHAR(10) = 'n1',
    @two VARCHAR(10) = 'n2',
    @three VARCHAR(10) = 'n3',
    @four VARCHAR(10) = 'n4',
    @five VARCHAR(10) = 'n5'
)
AS
BEGIN
SET NOCOUNT ON;

SELECT
    @one AS 'one',
    @two AS 'two',
    @three AS 'three',
    @four AS 'four',
    @five AS 'five'
END

//SAMPLE PHP CALL
$sp_name = 'mydb.dbo.myproc';
$proc = mssql_init($sp_name);
$sp_parms->one = 'one';
$sp_parms->two = 'two';
$sp_parms->three = 'three';

foreach ($sp_parms as $key=>$parm) {
    #THIS FAILS, because it's binding values!
    #mssql_bind($proc, '@'.$key, $parm, SQLVARCHAR)
    #    or die("Unable to bind $sp_name:$key<br>".mssql_get_last_message());
    #THIS SUCCEEDS, USES A REFERENCE
    mssql_bind($proc, '@'.$key, $sp_parms->$key, SQLVARCHAR)
        or die("Unable to bind $sp_name:$key<br>".mssql_get_last_message());
}

mssql_close> <Mssql Functions
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites