Msphpsql: PDOException: String data, right truncation when insert a long string

Created on 7 Oct 2016  路  11Comments  路  Source: microsoft/msphpsql

Hi all,

I have try to insert a long string into database, but experience the exception: _[Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation_

I am using php7.0.8 and tried both PDO_SQLSRV and SQLSRV for linux driver...

I notice that the issue happen

  • When using prepare statement -> execute.
  • The connection is establish in UTF-8 character set.
  • The string need to long enough ( > 2600 bytes )

Table Schema:

CREATE TABLE dummy_message
(
    id INT PRIMARY KEY NOT NULL IDENTITY,
    message NVARCHAR(MAX)
);

I have prepare PHP script to describe the problem: https://gist.github.com/kevinchl/88edf9b51d79605dd7e32cfac0d04778

Current result:

Fatal error: Uncaught PDOException: SQLSTATE[22001]: [Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation in test.php
Stack trace:
#0 /home/vagrant/code/test.php(16): PDOStatement->execute(Array)
#1 /home/vagrant/code/test.php(35): test_insert('Gluten-free Die...')
#2 {main}
  thrown in /home/vagrant/code/test.php on line 16
Linux bug

Most helpful comment

@kevinchl We are looking into this

All 11 comments

@kevinchl We are looking into this

@meet-bhagdev Will a release with a fix for this issue and #163 be available soon?

We confirm the issue on Ubuntu 14.04, php7.0.10 compiled with PDO_SQLSRV and SQLSRV for linux drivers.
Looking forward see a fix for this.

We also confirm this issue running PHP 7.0.8-0ubuntu0.16.04.3 . Any planned resolution time? Field type text in our case.

This should be fixed with our latest release. You can upgrade using PECL: https://github.com/Microsoft/msphpsql/tree/PHP-7.0-Linux#install

If you need the binaries, we will be releasing them soon on GitHub

Confirmed that release 4.0.7.0 fixes this issue.

Hi Meet-bhagdev,

I saw that this post dated from 2016 but I'm facing the same issue.
I'm working on PHP 7.3.10, SQLSRV ODBC Driver 17 and MS SQL Server 2008.

error : [Microsoft][ODBC Driver 17 for SQL Server]String data, right truncation

this is my request : "SELECT * FROM TIERS WHERE T_TIERS='953505'"

T_TIERS type is string that's why is quoted
The same query works fine in SQL Studio
@meet-bhagdev is that bug should be fix?

@Drick-Ce if you're unaware, SQL Server 2008 and SQL Server 2008 R2's extended support ended on July 9, 2019.
If you like, please create a new issue with more details, especially the versions of pdo_sqlsrv and ODBC drivers

@yitam I'm using ODBC Drivers 17.

Are you using Windows or Linux? The latest ODBC driver 17.5.2?
To help you we need to know more. Please create a new issue @Drick-Ce

Thanks @yitam I'm using ODBC Driver 17.3
I've tested PDO_SQLSRV 5.6.1 and it's working fine.
thanks for your help.

Was this page helpful?
0 / 5 - 0 ratings