-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bind #699
Comments
Update: if we omit "CharacterSet' => 'UTF-8'" on the script's connection options, there's no error but returns $outParams as zero, which is wrong. Further analysis showed that it does not change it's value. |
Hi @fmart8
You provided two placeholders when calling your stored procedure, but you only expect one output parameter. Perhaps, you meant to do this |
Hello @yitam, Yes the procedure call should have a single placeholder. I started with an example from Microsoft (that, incidently, placed no "&" before the bound variable) and started adding things to try to replicate the error. The extra "?" was a mistake I made when doing minor modifications before uploading the script. About what I'm trying to do, just some store procedure that inserts a record and returns a value in a OUT variable. The only thing a little less straightforward, IMO, is that it uses a TRY CATCH block to detect duplicate records. Can you test the script on a system similar to mine? |
Hi @fmart8 Please let me know if I have misinterpreted your stored procedure, which I've reconstructed based on your input (see below). It seems that you want to attempt the following: My first response to you above was whether you intentionally made this call to procedure fail, because temp2 is supposedly empty. That's why I don't understand what you were trying to do. Is your goal to set
|
@yitam, Note that this is not actual production code. It's just a script to nail down the circumstances of the error. The point is that that script fails in two Windows systems with PHP7.2.2 and SQL Server 2012, no matter the contents of the "temp" tables. Thanks for you help. |
@fmart8 I suppose you closed this issue by accident? Thank you for the updated script, so much clearer now. I will investigate more, but in the meantime, if I change your stored procedure as shown below, the outparam is set to 123. Is 123 what you expected?
|
@yitam, The result should always be 123 on $outParam. But this error occurs: The change you made defeats the purpose of the script. Those two tables (temp and temp2) and that particular INSERT SELECT are there expressly to expose the bug. I'm sorry for not having being as clear as I could. I thought that the script would make spotting the bug (on affected systems) straightforward, but I sure could have done better. Thanks for your concern, yitam. |
Yes @fmart8 I understand what you're trying to prove now. I'll do some investigation and get back to you. Thanks for your patience. |
Hi @fmart8 Upon some brief investigation, it's something to do with encoding, as you have already pointed out. If I changed this line
This is my output:
I want to know if this is what you expected. If not, please let me know what you expect. Thanks! |
@yitam, Thanks. |
Thanks @fmart8 |
I updated the test script (http://maisqi.com/outros/bugs/bind-error-test.php.txt) so that it initializes $outParam to 321 before calling the stored procedure. In a nutshell, the procedure should return 100 or 123 and no other (unless the INSERT INTO fails but that's about impossible because it always inserts zero records). |
@fmart8 I think you meant The problem probably lies in this line Anyway, I see your point and will continue my investigation. |
Hello @yitam. |
@fmart8 Upon investigation, it looks like you need to specify the SQL type of the output parameter when calling sqlsrv_query(). Please change
to
and let us know if this fixes the problem. Thanks! |
@david-puglielli,
Anyway, I updated the script to reflect your suggestion: But please do not mark this as solved for the reasons I exposed above. |
Thank you @fmart8, you are right that it is a bug. We will continue investigating and keep you updated. Please let us know if you run into this bug again, especially if the workaround fails in any circumstance. |
Fixed in 5.2.1-preview. Please reopen the issue if otherwise, @fmart8. |
+## Driver version or file name
+Please tell us what the PHP driver version or file name is.
+5.2.0RC1
+## SQL Server version
+Please tell us what the SQL Server version is.
+## Client operating system
+Please tell us what oprating system the client program is running on.
+Windows 10 64 bits
+## PHP version
+Please tell us which version of PHP you are running.
+7.2.2 64bits Non Thread Safe
+## Microsoft ODBC Driver version
+Please tell us which version of the Microsoft ODBC Driver you are using.
+13
+## Table schema
+Please tell us the table schema
+Might not be related to a specific table. Please see script.
+## Problem description
+Please share more details with us.
+Can't get output params values from a stored prcedure; the routine returns garbage or
the script hangs.
I tried narrowing the problem down and it seams that it only happend when the procedure:
Tested under:
And:
It did work on this machine, that runs PHP7.1:
+## Expected behavior and actual behavior
+Please tell us what should happen and what happened instead
Instead, it throws an error saying "An error occurred translating string for an output param to UTF-8: O parametro está incorreto." (incorrect parameter).
+## Repro code
'...', 'ConnectionPooling' => 1, 'CharacterSet' => 'UTF-8', 'UID' => '...', 'PWD' => '...', ]; $conn = sqlsrv_connect($instance, $cfg); if( $conn === false ) { echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } echo "Connected...\n"; ################################################################################ // Recreate tables and routines. sqlsrv_query( $conn, 'DROP PROCEDURE temp__exp2'); sqlsrv_query( $conn, 'DROP TABLE temp'); sqlsrv_query( $conn, 'DROP TABLE temp2'); sqlsrv_query( $conn, 'CREATE TABLE temp (correio_electronico NVARCHAR(50), nome NVARCHAR(50), telefones NVARCHAR(15), id_entidade INT)'); sqlsrv_query( $conn, 'CREATE TABLE temp2 (estado TINYINT NOT NULL DEFAULT 0)'); echo "Create routine...\n"; $sql = " CREATE PROCEDURE temp__exp2 @outParam INT OUTPUT AS BEGIN SET @outParam = 100; INSERT INTO temp (correio_electronico, nome, telefones, id_entidade) SELECT '[email protected]', 'Teste', 'xxx', 1 FROM temp2 CC WHERE CC.estado = 100 ; BEGIN TRY SET @outParam = 123; END TRY BEGIN CATCH END CATCH END"; $stmt2 = sqlsrv_query($conn, $sql); if ($stmt2 === false) { echo "Error in executing statement 2.\n"; die( print_r( sqlsrv_errors(), true)); } ################################################################################ // Call routine. echo "Call routine...\n"; $tsql_callSP = "{call temp__exp2(?, ?)}"; $outParam = 1; $params = array( array(&$outParam, SQLSRV_PARAM_OUT) ); $stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params); if( $stmt3 === false ) { echo "Error in executing statement 3.\n"; print_r(sqlsrv_errors()); die("\n** ERROR! **\n"); } // Read all. while($res = sqlsrv_next_result($stmt3)); ################################################################################ // Print out param. echo "\$outParam: $outParam.\n"; // Free handles. sqlsrv_free_stmt( $stmt2); sqlsrv_free_stmt( $stmt3); sqlsrv_close( $conn); echo "Done.\n";+Please share repro code with us, or tell us how to reproduce the issue.
Please try the following script:
The text was updated successfully, but these errors were encountered: