note 76937 added to function.mssql-bind
| From: | fheald at buzztime dot com | Date: | Mon, 06 Aug 2007 19:27:13 +0000 |
| Subject: | note 76937 added to function.mssql-bind | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129235@lists.php.net to get a copy of this message | ||
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());
}
----
Server IP: 208.69.120.35
Probable Submitter: 216.10.235.110
----
Manual Page -- http://www.php.net/manual/en/function.mssql-bind.php
Edit -- https://master.php.net/note/edit/76937
Del: integrated -- https://master.php.net/note/delete/76937/integrated
Del: useless -- https://master.php.net/note/delete/76937/useless
Del: bad code -- https://master.php.net/note/delete/76937/bad+code
Del: spam -- https://master.php.net/note/delete/76937/spam
Del: non-english -- https://master.php.net/note/delete/76937/non-english
Del: in docs -- https://master.php.net/note/delete/76937/in+docs
Del: other reasons-- https://master.php.net/note/delete/76937
Reject -- https://master.php.net/note/reject/76937
Search -- https://master.php.net/manage/user-notes.php