Skip to content
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

PHP Fatal error: Unexpected SQL type encountered in calc_string_size #127

Closed
xalopp opened this issue Aug 6, 2016 · 7 comments
Closed
Labels

Comments

@xalopp
Copy link

xalopp commented Aug 6, 2016

On Linux, I get with the sqlsrv driver a Fatal error with following Fatal error

PHP Fatal error:  Unexpected SQL type encountered in calc_string_size

when I execute this query:

select current_value from sys.sequences

The same query works well with the PDO driver pdo_sqlsrv.

Linux Version: Ubuntu 16.04, PHP installed as package.
PHP Version: PHP 7.0.9-1+deb.sury.org~xenial+1 (cli) ( NTS )
pdo_sqlsrv ExtensionVer => 4.0.2.0
sqlsrv ExtensionVer => 4.0.2.0

@xalopp
Copy link
Author

xalopp commented Aug 6, 2016

I use the scripts https://github.com/xalopp/vagrant-php7sqlsrv/blob/master/tests/pdo_sqlsrv_query.php and https://github.com/xalopp/vagrant-php7sqlsrv/blob/master/tests/sqlsrv_query.php for testing.

$ MSSQL_SQL='select current_value from sys.sequences' /vagrant/tests/sqlsrv_query.php
PDO sqlsrv connection successfull: yes
PDO sqlsrv query successfull: yes
PHP Fatal error:  Unexpected SQL type encountered in calc_string_size. in /vagrant/tests/sqlsrv_query.php on line 31

@meet-bhagdev
Copy link
Contributor

Hello @xalopp,

We are trying to repro this in our test lab with no luck. Can you add $count to your script and share your results?

$count = 0;
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
                $count++;
                // var_dump($row);
}
sqlsrv_free_stmt($result);
echo "rows = ".$count."\n";

@xalopp
Copy link
Author

xalopp commented Aug 12, 2016

The program still fails at the line containg

while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {

I forgeot to mention I'm using:

Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) 
    Apr 29 2016 23:23:58 
    Copyright (c) Microsoft Corporation
    Enterprise Evaluation Edition (64-bit) on Windows Server 2012 R2 Essentials 6.3 <X64> (Build 9600: ) (Hypervisor)

@xalopp
Copy link
Author

xalopp commented Aug 12, 2016

sqlcmd -S 192.168.56.102 -d AdventureWorks2016CTP3 -U test -P test -Q 'create sequence test123 start with 123'
php /vagrant/tests/sqlsrv_query_sequences.php
PHP Fatal error:  Unexpected SQL type encountered in calc_string_size. in /vagrant/tests/sqlsrv_query_sequences.php on line 13
PHP Stack trace:
PHP   1. {main}() /vagrant/tests/sqlsrv_query_sequences.php:0
PHP   2. sqlsrv_fetch_array() /vagrant/tests/sqlsrv_query_sequences.php:13
<?php

$serverName = getenv('MSSQL_SERVERNAME') ?: '192.168.56.102';
$database   = getenv('MSSQL_DATABASE') ?: 'AdventureWorks2016CTP3';
$username   = getenv('MSSQL_USERNAME') ?: 'test';
$password   = getenv('MSSQL_PASSWORD') ?: 'test';

$sqlStatement = getenv('MSSQL_SQL') ?: 'select current_value from sys.sequences';


$conn = sqlsrv_connect($serverName, ['Database' => $database, 'Uid' => $username, 'PWD' => $password]);
$result = sqlsrv_query($conn, $sqlStatement);
$row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC);
sqlsrv_free_stmt($result);

Chaing the query to

select cast (current_value as int) from sys.sequences

will work. But it should work without CASTing, like the pdo_sqlsrv does.

@xalopp
Copy link
Author

xalopp commented Sep 6, 2016

The drivers doesn't support the SQL data type sql_variant, which is used in sys.sequences.

The easiest way to reproduce this:

sqlsrv_query($conn, "DECLARE @v1 sql_variant; SET @v1 = 'ABC'; SELECT @v1;");

@Hadis-Knj
Copy link

@xalopp we added sql_variant support in the 4.2.0-preview, could you confirm that this issue if fixed?

@xalopp
Copy link
Author

xalopp commented May 26, 2017

@Hadis-Fard I successfully tested the query with 4.2.0-preview. Thanks!

@xalopp xalopp closed this as completed May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants