/    Sign up×
Community /Pin to ProfileBookmark

Script not showing a result in php if I change a condition in sql.

I am using[B] mssql_query[/B]. I have this sql query that have [B]joins[/B] and [B]distinct[/B]. If I change the condition value it will not show a result when run as a php script. But if I run that query directly in a sql server browser, it will show results.

For example below, if I change the condition [B]SOTYPE = ‘aaa’[/B] to [B]SOTYPE = ‘bbb’[/B],it will not show any result if it will be run as php script.But using directly the sql server browser, it will display results.

Now if the condition is [B]SOTYPE = ‘aaa’[/B] it will also show results,run as php script. Now removing [B]distinct[/B] it will show results(run as php script) no matter what conditions that I do.

Is this php memory related? How can I solve this problem?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@r8rApr 27.2015 — This may be due to escaping issues and maybe you need to use GROUP BY also. However, without actually seeing a little more of your code and queries, I'm just stabbing in the dark.
Copy linkTweet thisAlerts:
@anishgiriauthorApr 27.2015 — [i][noparse][Edited to replace tags with and [code=php] tags as appliable. ~ Mod.][/noparse][/i]

This may be due to escaping issues and maybe you need to use GROUP BY also. However, without actually seeing a little more of your code and queries, I'm just stabbing in the dark.[/QUOTE]

My php code is just composed of this query and trying to see if it will show results.
[code]
SELECT DISTINCT prd.ZSD_OMSH.*, prd.KNA1.NAME1 AS K_NAME1, prd.KNA1.NAME2 AS K_NAME2, prd.ZSD_OMSD.WERKS, prd.ZSD_OMSD.LGORT, prd.KNA1.NAME3 AS K_NAME3, prd.KNA1.NAME4 AS K_NAME4, prd.PA0001.ENAME FROM prd.ZSD_OMSH INNER JOIN prd.KNA1 ON prd.ZSD_OMSH.KUNNR = prd.KNA1.KUNNR INNER JOIN prd.PA0001 ON prd.ZSD_OMSH.PERNR = prd.PA0001.PERNR INNER JOIN prd.ZSD_OMSD ON prd.ZSD_OMSH.ORDNUM = prd.ZSD_OMSD.ORDNUM where prd.ZSD_OMSH.ERDAT >= '20150301' and prd.ZSD_OMSH.ERDAT <= '20150424' and prd.ZSD_OMSH.MANDT = '888' and prd.KNA1.MANDT = '888' and prd.PA0001.MANDT = '888' and SOTYPE = 'ZKB' and ((DISAPPROVE is null) or (DISAPPROVE <> 1)) and ((VSTATIMD2 is null) or (VSTATIMD2 IN('0',''))) and NEXT_APP = '4'

[code=php]
$rs = mssql_query($sql);
if (mssql_num_rows($rs) > 0) {
while ($row = mssql_fetch_array($rs)) {

echo "result";
}
}[/code]


This sql query above will show result if I directly use sql server browser. But if I run it as a php script it will not show result. But if i change the condition [B]SOTYPE = 'ZKB' to SOTYPE = 'ZOR'[/B], it will show result on my php script.
Copy linkTweet thisAlerts:
@ginerjmApr 27.2015 — Have you checked your error log for any messages? Or better yet, have you enabled error checking so that error messages will display onscreen for you? (See my signature.)
Copy linkTweet thisAlerts:
@NogDogApr 27.2015 — For now, I would double-check that the query being submitted is actually what you think it is:
[code=php]
$rs = mssql_query($sql);
if (mssql_num_rows($rs) > 0) {
while ($row = mssql_fetch_array($rs)) {

echo "result";
}
}
else {
echo "<pre>DEBUG (num rows 0):n$sql</pre>";
}
[/code]

Then you can copy/paste the SQL exactly as it was at that point in the script and see what you get.
Copy linkTweet thisAlerts:
@anishgiriauthorApr 28.2015 — For now, I would double-check that the query being submitted is actually what you think it is:
[code=php]
$rs = mssql_query($sql);
if (mssql_num_rows($rs) > 0) {
while ($row = mssql_fetch_array($rs)) {

echo "result";
}
}
else {
echo "<pre>DEBUG (num rows 0):n$sql</pre>";
}
[/code]

Then you can copy/paste the SQL exactly as it was at that point in the script and see what you get.[/QUOTE]


Yeah I think it's the actual query that is being submitted because actualy the sql query that I posted here is the one that I [B]echo/print[/B]. Turning on error message log it says.

Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in c:inetpubwwwrootermsapoms_approval_report_sap.php on line 334.

But just now, the script is already showing result/data. And I did not modify any code. There are many people trying to access this data a while ago. Maybe the data that is being retrieve is just to huge and this cause this sql error?
Copy linkTweet thisAlerts:
@NogDogApr 28.2015 — I suppose there could me several potential reason, which is why it's always a good idea to check the return value of a call to *_query() and make sure it didn't choke on something. I'm not conversant with mssql_*() functions, but it looks like you could use mssql_get_last_message() to find out what happened, as in the example on the manual page: http://php.net/manual/en/function.mssql-get-last-message.php . (In the ultimate production code, you probably don't want to die() and spew debug info, but instead error_log() the info and display some sort of "nice" error page. ? )
×

Success!

Help @anishgiri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...