CamW Posted July 7, 2006 Share Posted July 7, 2006 Hi all,I'm having a peculiar problem where PHP is occasionally returning incorrect results on a query. I'm connecting to the db like so:[code]$conn =& ADONewConnection('odbc_mssql');$dsn = "Driver={SQL Server};Server=$server;Database=$db;"; $conn->Connect($dsn, $dBUser, $dBPass);[/code]This works fine. Then, I execute a sql statement like so:[code]$result = $conn->Execute($query);[/code]Again, this works fine, and these code snippets exist in a function that I've been using for months now, and I've had no problems with any other scripts accessing the database. However, today I noticed some database results that looks suspicious, and upon further inspection, the query was indeed returing returning results inconsistent with the data in the database. To debug, I threw in some echo commands to see what was going on:[code]echo $query . "<br />";$result = $conn->Execute($query);echo "<pre>";print_r($result->fields);echo "</pre>";[/code]One of the queries that was returning incorrect data was this:[code]SELECT COUNT(id) AS theCount FROM ccwilki2.tblAnswer WHERE answer = 'Natalie Poole' AND survey_id = 17 AND question_id = 31[/code]Upon executing this query, the print_r of the $result->fields array revealed that $conn->Execute had returned an incorrect number (0). The really weird thing is, if I cut and paste this query directly into the SQL Server Management Studio and execute it, it gives the correct result (6)! That is without changing the query a bit. To me, it looks like the problem is coming from the $conn->Execute() function. Is this a bug? Have any of you encountered this problem before?The problem only occurs with a small minority of the queries, but the problem queries are always the same. I am certain that the connection created in PHP points to the same database as SQL Server Management Studio was accessing when I checked the results. The script username only has access to one mssql database, and I signed on to management studio with that username.Any help would be most appreciated! This is making me go prematurely gray! Thanks in advance.-Cameron Quote Link to comment https://forums.phpfreaks.com/topic/13956-php-returning-incorrect-results-from-a-query/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.