Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS SQL Query failed in PHP but not in MS SQL Server Management Studio

Tags:

sql

php

I execute this query with php and odbc driver

$sql="DECLARE @Auftrag int; 
DECLARE @date_now datetime = getdate(); 
EXEC @Auftrag=EHS.dbo.SP_ANZEIGE 
@Tablet=1, 
@Status=0, 
@KuNr='K015538'; 
SELECT 'generatedID'=@Auftrag;";

$res = odbc_exec($db1_link, $sql) or die(odbc_errormsg()); // returns resource(13)
$firstRow = odbc_fetch_array($res); // dies error

If i do odbc_fetch_array the error "No tuples available at this result index" is thrown.

If I run the exact same query in Management Studio everything works fine. It shows me the computed generatedID. What is the difference?

greets Alex

like image 655
alex Avatar asked Feb 12 '26 20:02

alex


1 Answers

Try to prefix the query with:

set nocount on

That prevents SQL Server from sending rowcount updates, which UNIX clients sometimes mistake for actual rowsets

like image 174
Andomar Avatar answered Feb 15 '26 10:02

Andomar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!