Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Microsoft SQL Server Functions : mssql_bind

mssql_bind

Adds a parameter to a stored procedure or a remote stored procedure (PHP 4 >= 4.0.7, PHP 5, PECL odbtp:1.1.1-1.1.4)
bool mssql_bind ( resource stmt, string param_name, mixed &var, int type [, int is_output [, int is_null [, int maxlen]]] )

Example 1375. 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), SQLVARCHAR, false, false, 150);
mssql_bind($sp, "@quantity", stripslashes($newquantity), SQLVARCHAR, false, false, 50);

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

?>

Code Examples / Notes » mssql_bind

fheald

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
".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
".mssql_get_last_message());
}


Change Language


Follow Navioo On Twitter
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
eXTReMe Tracker