sql server - SqlServer stored procedure called from php doesn't return integer output correctly -
I'm trying to get a SQL Server 2008 database using php mssql functions out of a stored procedure. Code errors run iwthout, but I'm getting back to a strange vlaue one of my production standards
stored procedure code: ..
create procedure [dbo] [check_barcode_and_return] @Barcode nvarchar (20), @IsInDatabase integer output, selected as @Product_Info nvarchar (100) output @IsInDatabase = COUNT (*) dbo. product_info WHERE barcode = @Barcode declared select brand @Brand varchar (45) set to announce @Brand = @Description varchar (dbo.product_info WHERE barcode = @Barcode) (50) set @Description = (product_desc dbo.product_info Choose where barcode = @Barcode) select @Product_Info = @Brand + '_' + @Description returns GO
the php code that says:
& lt; Php // is used in one barcode to access the database $ barcode_yes = '11335577'; // $ barcode_no = '0011223344' use a sbarcode not in the database; $ Host = '00 .000.000.000 '; $ Db = 'dbName'; $ User = 'username'; $ Password = 'password'; $ Barcode inDB = 0; $ ProductInfo = ""; Try {$ conn = mssql_connect ($ host, $ user, $ password); Mssql_select_db ($ db, $ conn); $ Stmt = mssql_init ('check_barcode_and_return', $ conn); Mssql_bind ($ stmt, '@Barcode', $ barcode_yes, SQLVARAR, incorrect, false, 20); Mssql_bind ($ stmt, '@IsInDatabase', $ barcode indB, SQLINT1, true, false, 1); Mssql_bind ($ stmt, '@Product_Info', $ productInfo, SQLVARCHAR, true, false, 100); Mssql_execute ($ stmt, true); Echo 'positive examination results:'. "\ N"; Echo output $ barcode indi = '. $ Barcode indi "\ N"; Copy '$ productInfo =' $ SampleInfo "\ N"; // reset for next call mssql_free_statement ($ stmt); $ Barcode inDB = 0; $ ProductInfo = ""; $ Stmt = mssql_init ('check_barcode_and_return', $ conn); Mssql_bind ($ stmt, '@Barcode', $ barcode_no, SQLVARARAR, False, False, 20); Mssql_bind ($ stmt, '@IsInDatabase', $ barcode indB, SQLINT1, true, false, 1); Mssql_bind ($ stmt, '@Product_Info', $ productInfo, SQLVARCHAR, true, false, 100); Mssql_execute ($ stmt, true); Resonance 'Negative Exam Results:' "\ N"; Echo output $ barcode intact = '. $ Barcode indi "\ N"; Echo '$ productInfo ='. $ ProductInfo. "\ N"; Mssql_close ($ Conn); } Hold (exception $ e) {echo $ e-> GetMessage (); }? & Gt;
When I run this from the command line, this is the result:
positive test results: Production $ barcodeInDB = 968529665 $ productInfo = Heinz_tomato ketchup run negative test results: production $ barcodeInTable = 968529664 $ productInfo = _
access stored procedure barcode If I directly using SQL server management Studio, use up, I Get @BarcodeInDB = 1 and for positive @BarcodeInDB = 0 for negative A
Code
What parameters do I need to get the correct value for the integer output parameter? I want to force my output parameter as a SQLINT4 in the integer data type because apparently, T-SQL
Integer variables are 4-byte integers, trying to force them into a datatype with small capacity (i.e. SQLINT1, SQLINT2 or SQLBIT) results in unexpected output results.
Therefore, I changed it ...
.. mssql_bind ($ stmt, '@IsInDatabase', $ barcodeInDB, SQLINT4, true); ...
And it worked fine.
Comments
Post a Comment