Jump to content

PHP returning incorrect results from a query


CamW

Recommended Posts

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.