A note to anyone trying to bind a DATETIME (which is apparently unsupported): Just use the SQLVARCHAR type to pass your DATETIME values.
This worked for me with formats such as 01/01/1900 and 01-01-1900.
mssql_bind
説明
bool mssql_bind ( resource stmt, string param_name, mixed &var, int type [, int is_output [, int is_null [, int maxlen]]] )| 警告 |
この関数は、 現在のところ詳細な情報はありません。引数のリストのみが 記述されています。 |
mssql_execute()、 mssql_free_statement() および mssql_init() も参照ください。
mssql_bind
dietcheese
03-Oct-2006 06:41
03-Oct-2006 06:41
tim at howarth dot uk dot com
18-Apr-2005 07:47
18-Apr-2005 07:47
The behavior appears to be different on windows (using
dbnetlib) and linux (using freetds)
On windows, one could miss out the optional parameters.
On linux, the optional parameters aparently need to be
supplied (or at least I got spurious errors)
which stopped when I added them!
I was using XAMPP (which gives me apache, php5, and
freetds in one easy shot!) on FC3.
Code example:
$cn = mssql_connect($DBSERVER, $DBUSER, $DBPASS);
mssql_select_db($DB,$cn);
$sp=mssql_init("WDumpAdd"); // stored proc name
mssql_bind($sp, "@productname",
stripslashes($newproduct),
SQLVARCHAR,FALSE,FALSE,150);
mssql_bind($sp, "@quantity",
stripslashes($newquantity),
SQLVARCHAR,FALSE,FALSE,50);
mssql_execute($sp) or die("could not perform insert");
mssql_close($cn);
hope this helps
Tim
Anonymous
15-Jan-2005 12:57
15-Jan-2005 12:57
You do not have to use mssql_query to pass parameters longer than 255 characters to a stored proc. All you have to do is define the "type" of the field to be SQLTEXT.
matt at austincc dot edu
09-Apr-2003 09:27
09-Apr-2003 09:27
two things to keep in mind if you are having trouble binding output parameters:
1) you need to pass your php variable by reference. mssql_bind($stmt, "@outParam", &$outParam, true)
2) php-4.3.1-win32 had a binding bug and output parameters do not bind. 4.1 and 4.3.2rc1 do not have the bug. I have not tested other versions.
fjortizATcomunetDOTes
26-Dec-2001 10:18
26-Dec-2001 10:18
After creating a statement resource with
mssql_init, you can bind all the
parameters. These are the arguments:
- stmt: statement resource obtained with
mssql_init
- param_name: string with the parameter
name. YOU HAVE TO INCLUDE the @
character, like the T-SQL syntax. See
the full example that I'll include in
mssql_execute explanation.
- var: this is the PHP variable you'll
bind the MSSQL parameter to. You can
pass it BY VALUE, but you can also pass
it BY REFERENCE (&var), to retrieve
OUTPUT and RETVAL values after procedure
execution.
The return value (a long integer value)
is treated like a special OUTPUT
parameter, called "RETVAL" (without the
@). See the example at mssql_execute to
see how it works.
- type: one of this new supported
PHP constants.
SQLTEXT, SQLVARCHAR,SQLCHAR,
SQLINT1,SQLINT2, SQLINT4,
SQLBIT,SQLFLT8
See notes on bottom of this contribution
for the tricks, quirks and DB-lib bugs
related to the types.
- is_output: boolean value to say
whether the value is an OUTPUT parameter
or not. If it's an OUTPUT parameter but
you say nothing or FALSE, it will be
treated as a normal input parameter
and no error will be yielded.
- is_null: to say the parameter is NULL.
Don't pass an empty PHP variable to
achieve this, it won't work. Use this boolean value.
- 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 maxlen must be 50.
Bugs in MSSQL DB-lib, quirks, etc...
- You can't modify and get a "char(n)
OUTPUT" parameter. I tried from "Query
Analyzer" and I get the same results.
There must be a bug in MSSQL client
libs.
You can get output from a varchar(n),
though.
- The only float type needed for
"float","double" and "decimal(n,m)"
parameters is SQLFLT8, I don't know why
but SQLFTL4 and SQLFLTN don't work
properly for OUTPUT parameters.
- There is a bug in MSSQL Client
Libraries that avoid sending varchar
parameters for more than 255 characters
to a stored procedure.
Use mssql_query instead.