Sending a Serious Query to MSSQL
| From: | Flint Doungchak | Date: | Fri, 05 Jan 2001 00:54:17 +0000 |
| Subject: | Sending a Serious Query to MSSQL | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-4822@lists.php.net to get a copy of this message | ||
Hello all,
Hope you had a great New Year. I have a question about the MS_SQL module. I
have a query, below, which works great in query analyzer but when I send it
to PHP, it chokes. The code kind of looks like this:
$query = "SET NOCOUNT ON
SELECT DISTINCT broadcasts.brodid,'play' = SUM(CASE
WHEN playlists.playid IS NOT NULL THEN '1'
ELSE 0
END)
INTO #temptable FROM programs
JOIN broadcasts
ON programs.progid = broadcasts.progid
LEFT JOIN playlists
ON broadcasts.brodid = playlists.brodid
WHERE programs.progid = 141 GROUP BY broadcasts.brodid ORDER BY play
SET NOCOUNT OFF
SELECT * FROM #temptable as test JOIN broadcasts
ON test.brodid = broadcasts.brodid";
$result = mssql_query($query,$connect);
As you can see, I send multiple commands to SQL server, rather than one.
Now, $result doesn't return a valid identifier if I use the method above.
If I break the query into individual pieces and send them to SQL server via
PHP individually, it works fine. However, what are the resource implications
of this? Does it actually connect to the server 4 times? Anyone really give
a crap? :)
Thanks in advance.
-Flint