Been looking for this on Google for a while, but still looking. Couldn't turn up anything on it.
Using PHP to query MS SQL Server via ODBC. Code is below: (I've watered it down to bare-bones as I've tried to debug this)
$SQL=<<<HEREDOC
DECLARE @weekStart SMALLDATETIME;
SET @weekStart = DATEADD(d,0, DATEDIFF(d,0,GETDATE()));
SET @weekStart = DATEADD(d, 1-DATEPART(dw, GETDATE()), @weekStart);
SELECT
DATEDIFF(week, Run_Date, @weekStart)
AS weeksAgo
,MIN(Current_List) AS list
,COUNT(*) AS cnt
,SUM(NoContact_90Days) AS noContact90
,SUM(NoContact_180Days) AS noContact180
,SUM(NoMtg_180Days) AS noMtg180
,SUM(NoMtg_360Days) AS noMtg360
FROM
[someDB].[DBO].[someTable]
WHERE
Current_List<>''
GROUP BY
DATEDIFF(week, Run_Date, @weekStart)
,Current_List
ORDER BY DATEDIFF(week, Run_Date, @weekStart)
;
HEREDOC;
$dbUser = "someUser";
$dbPass = "somePw";
$connStr = 'Driver={SQL Server};Server=someServer;';
$conn = odbc_connect($connStr, $dbUser, $dbPass)
or die("Cannot start ODBC connection");
$rs = odbc_exec($conn, $SQL);
$r = odbc_fetch_array($rs);
die('ok');
Getting a warning I've never seen on the odbc_fetch_array() line:
Message: odbc_fetch_array() [function.odbc-fetch-array]: No tuples available at this result index
I've run the query in SQL Server Mgmt Studio and it returns a single set of records. I'm using this same connection string & method of retrieving the rows in other parts of the app with no problem. Any ideas?