framework: Eloquent on MSSQL return error SQLSTATE[IMSSP]: Field 2 returned no data.

Laravel Version

10.23.1

PHP Version

8.1.23

Database Driver & Version

php-sqlsrv-5.11.0-1.el9

Description

OS: Alma 9

After minor update to PHP php-8.1.23-1.el9.remi.x86_64 and SQL_SRV php-sqlsrv-5.11.1-1.el9.remi.8.1.x86_64, my app broke, throw error for simple Eloquent call:

   $client= BusinessPartner::first();

Model

namespace App;

use Illuminate\Database\Eloquent\Model;

class BusinessPartner extends Model {
    protected $connection = 'sqlsrv';
    protected $table = 'dbo.OCRD';
    protected $primaryKey = 'DocEntry';
    public $timestamps = false;
}

Error:

SQLSTATE[IMSSP]: Field 2 returned no data.

select top 1 * from [dbo].[OCRD]

The above raw query (generated by Laravel) works perfectly if I run in a native SQL client.

Before upgrading, my app works perfectly fine.

Steps To Reproduce

Model

namespace App;

use Illuminate\Database\Eloquent\Model;

class BusinessPartner extends Model {
    protected $connection = 'sqlsrv';
    protected $table = 'dbo.OCRD';
    protected $primaryKey = 'DocEntry';
    public $timestamps = false;
}

(or whatever model, it will break anyway)

Tinker (or controller)

$client = BusinessPartner::first();

This line will throw error.

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 27 (8 by maintainers)

Most upvoted comments

Is it possible that this is involved?

microsoft/msphpsql#1478

Thank you, it’s not. I have 'trust_server_certificate' => 'true', in config/database.php and the other functions connect to DB normally. It’s just the query, not the connection.

Update: If I select some fields, it works

$client = BusinessPartner::where('CardCode', $CardCode)->select('CardName')->first() works (added ->select('CardName')). Why is that?

Can you test with Laravel Framework version before the whole PDO issue solved the problem? This can eliminate if any recent changes would cause any issue.

Gonna go on a hunch and say it’s related to https://github.com/laravel/framework/issues/47937. I’m not sure why things broke for you but if it broke while updating mssql dependencies then it doesn’t looks like a Laravel issue to me.