|
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)
Example 1375. mssql_bind() Example<?php Code Examples / Notes » mssql_bindfheald
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 Languagemssql_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 |