RE: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-17 Thread Weaver Hickerson
Follow up-
We solved this by moving that hugemongous query into a stored procedure.  Not 
the most elegant fix but until we get to PHP5 and native driver, etc it seems 
our only fix.



-Original Message-
From: Krister Karlström [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 05, 2008 2:04 PM
To: Weaver Hickerson
Cc: PHP DB
Subject: Re: [PHP-DB] PHP4, mssql_* and SQL Server 2005

Ouch! That was like the.. longest.. query that I've ever seen! I'm
surprised that it actually works and even more impressed that someone
actually figured that out... It might take a long time to run, since it
uses so many subqueries (if there's lots of data or even a moderate
amount of data). Are you sure there's no easier way to fetch your data?
Most subqueries can be re-written using a join and some more
where-comparisons instead...

Actually I'm more amazed that you actually can send that query and that
it works.. There's a slight chance that your problems might be solved by
rewriting that query... Maybe it's just to long or something, I don't
know. I will however not take the time to refactor that query... :)

Are you running PHP under Linux or Windows? You said that you only found
two queries that breaks? Wll, if the shorter ones works, but the longer
ones hangs, then maybe that's the problem...? :)

Regards,
Krister Karlström, Helsinki, Finland

Weaver Hickerson wrote:

 Krister -
 I've included the query below - If I paste it in query analyzer on 2000, or 
 2005 it works fine.

 Just coming through PHP4 to 2005, it hangs.  I actually don't get an error, 
 and then the browser says the server is too busy to handle the request.  
 Strange things like that. (I am using Zend Core with Apache and PHP 5).  I 
 will check for smalldatetime fields.


 SELECT   COUNT(DISTINCT C.CHART_ID) AS TOTAL,
  SUM(ISNULL(FEE_SCHEDULE.FEE,0) * UNITS) AS TOTALFEE
 FROM HL7 H,
  CHART C
  LEFT OUTER JOIN CHART_CODE D
  LEFT OUTER JOIN CHART_CODE_MODIFIER CCM
ON CCM.CHART_CODE_ID = D.CHART_CODE_ID
   AND CCM.CHART_CODE_MODIFIER_ID = (SELECT 
 MIN(CHART_CODE_MODIFIER_ID)
 FROM   
 CHART_CODE_MODIFIER
 WHERE  
 CHART_CODE_ID = D.CHART_CODE_ID)
  LEFT OUTER JOIN FEE_SCHEDULE
ON FEE_SCHEDULE.CPT_CODE = D.CHART_CODE
   AND FEE_SCHEDULE.START_DATE = (SELECT MSH_DTM
   FROM   HL7,
  CHART,
  
 CHART_CODE
   WHERE  
 CHART_CODE.CHART_ID = CHART.CHART_ID
  AND 
 CHART.HL7_ID = HL7.HL7_ID
  AND 
 CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
   AND FEE_SCHEDULE.END_DATE = (SELECT MSH_DTM
 FROM   HL7,
CHART,
CHART_CODE
 WHERE  
 CHART_CODE.CHART_ID = CHART.CHART_ID
AND 
 CHART.HL7_ID = HL7.HL7_ID
AND 
 CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
   AND FEE_SCHEDULE.SENDING_FACILITY = (SELECT 
 SENDING_FACILITY
FROM   HL7,
   
 CHART,
   
 CHART_CODE
WHERE  
 CHART_CODE.CHART_ID = CHART.CHART_ID
   AND 
 CHART.HL7_ID = HL7.HL7_ID
   AND 
 CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
   AND FEE_SCHEDULE.CODE_TYPE = 'pro'
   AND FEE_SCHEDULE.MODIFIER = CCM.MODIFIER
  LEFT OUTER JOIN FEE_SCHEDULE FS
ON FS.CPT_CODE = D.CHART_CODE
   AND FS.START_DATE = (SELECT MSH_DTM
 FROM   HL7,
CHART

Re: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-05 Thread Krister Karlström

Hi!

Have you checked that the query is escaped correctly? All single quotes 
(') needs to be escaped with another single quote, but that has been for 
MS-SQL all the time so I'll doubt that the problem is escaping.


Another issue I noticed is that SQL Server 2005 handles SMALLDATETIME 
coulmns slightly different, and the default formatting of the retuned 
date is in some collations different than in SQL Server 2000. So if you 
have any queries relying on a where clause that checks a SMALLDATETIME 
column you might need to adjust the date format.


Migrating to SQL 2005 might also cause some problems with character 
encoding, since SQL 2005 internally works with Unicode. At least for us 
who needs other characters than 7-bit ASCII... I had big trouble with 
moving ISO-8859-15 XML documents to a SQL Server 2005 Unicode server and 
parsing them into a native XML datatype (which is a really nice 
feature!), but the problems can be overcomed with a litte extra work...


You could also check that you use the correct protocol version of 
FreeTDS, if you're running PHP under Linux. I don't know how PHP 
connects to MS-SQL on Windows though.


Currently I have no other thoughts of what could cause your problems, at 
least without not being able to actually see the failed queries.


Regards,
Krister Karlström, Helsinki, Finland

Chris wrote:

Please always cc the mailing list so others can offer extra 
advice/suggestions etc.


Weaver Hickerson wrote:

they work in query analyzer.


ok so the queries aren't the problem.

do you get an error? what is it?

Might need to play with these settings:

http://www.php.net/manual/en/function.mssql-min-error-severity.php
http://www.php.net/manual/en/function.mssql-min-message-severity.php

And they seem to work on a new server I setup for testing that has 
ZendCore and on which I installed the Microsoft PHP driver and ported 
the code to that driver. :( 


That does seem to point to the driver, not sure what other suggestions I 
can offer.




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-05 Thread Weaver Hickerson
 = D.CHART_CODE_ID)
  AND FS.CODE_TYPE = 'pro'
  AND (FS.MODIFIER = ''
OR FS.MODIFIER IS NULL)
   ON D.CHART_CODE_ID IN (SELECT MIN(CHART_CODE_ID)
  FROM   CHART_CODE
  WHERE  CHART_ID = C.CHART_ID)
WHEREMSH_DTM = '10/01/2008'
 AND MSH_DTM  DATEADD(D,1,'10/31/2008')
 AND H.HL7_ID = C.HL7_ID
 AND CHART_CODE IN ('99281','99282','99283','99284',
'99285','99291')
 AND C.STATUS = 6
 AND H.SENDING_FACILITY = 'AEU'
ORDER BY 1



From: Krister Karlström [EMAIL PROTECTED]
Sent: Wednesday, November 05, 2008 3:31 AM
To: Weaver Hickerson
Cc: PHP DB
Subject: Re: [PHP-DB] PHP4, mssql_*  and SQL Server 2005

Hi!

Have you checked that the query is escaped correctly? All single quotes
(') needs to be escaped with another single quote, but that has been for
MS-SQL all the time so I'll doubt that the problem is escaping.

Another issue I noticed is that SQL Server 2005 handles SMALLDATETIME
coulmns slightly different, and the default formatting of the retuned
date is in some collations different than in SQL Server 2000. So if you
have any queries relying on a where clause that checks a SMALLDATETIME
column you might need to adjust the date format.

Migrating to SQL 2005 might also cause some problems with character
encoding, since SQL 2005 internally works with Unicode. At least for us
who needs other characters than 7-bit ASCII... I had big trouble with
moving ISO-8859-15 XML documents to a SQL Server 2005 Unicode server and
parsing them into a native XML datatype (which is a really nice
feature!), but the problems can be overcomed with a litte extra work...

You could also check that you use the correct protocol version of
FreeTDS, if you're running PHP under Linux. I don't know how PHP
connects to MS-SQL on Windows though.

Currently I have no other thoughts of what could cause your problems, at
least without not being able to actually see the failed queries.

Regards,
Krister Karlström, Helsinki, Finland

Chris wrote:

 Please always cc the mailing list so others can offer extra
 advice/suggestions etc.

 Weaver Hickerson wrote:
 they work in query analyzer.

 ok so the queries aren't the problem.

 do you get an error? what is it?

 Might need to play with these settings:

 http://www.php.net/manual/en/function.mssql-min-error-severity.php
 http://www.php.net/manual/en/function.mssql-min-message-severity.php

 And they seem to work on a new server I setup for testing that has
 ZendCore and on which I installed the Microsoft PHP driver and ported
 the code to that driver. :(

 That does seem to point to the driver, not sure what other suggestions I
 can offer.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-05 Thread Krister Karlström
,
 CHART,
 CHART_CODE
  WHERE  CHART_CODE.CHART_ID = 
CHART.CHART_ID
 AND CHART.HL7_ID = 
HL7.HL7_ID
 AND 
CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
  AND FS.SENDING_FACILITY = (SELECT SENDING_FACILITY
 FROM   HL7,
CHART,
CHART_CODE
 WHERE  
CHART_CODE.CHART_ID = CHART.CHART_ID
AND 
CHART.HL7_ID = HL7.HL7_ID
AND 
CHART_CODE.CHART_CODE_ID = D.CHART_CODE_ID)
  AND FS.CODE_TYPE = 'pro'
  AND (FS.MODIFIER = ''
OR FS.MODIFIER IS NULL)
   ON D.CHART_CODE_ID IN (SELECT MIN(CHART_CODE_ID)
  FROM   CHART_CODE
  WHERE  CHART_ID = C.CHART_ID)
WHEREMSH_DTM = '10/01/2008'
 AND MSH_DTM  DATEADD(D,1,'10/31/2008')
 AND H.HL7_ID = C.HL7_ID
 AND CHART_CODE IN ('99281','99282','99283','99284',
'99285','99291')
 AND C.STATUS = 6
 AND H.SENDING_FACILITY = 'AEU'
ORDER BY 1



From: Krister Karlström [EMAIL PROTECTED]
Sent: Wednesday, November 05, 2008 3:31 AM
To: Weaver Hickerson
Cc: PHP DB
Subject: Re: [PHP-DB] PHP4, mssql_*  and SQL Server 2005

Hi!

Have you checked that the query is escaped correctly? All single quotes
(') needs to be escaped with another single quote, but that has been for
MS-SQL all the time so I'll doubt that the problem is escaping.

Another issue I noticed is that SQL Server 2005 handles SMALLDATETIME
coulmns slightly different, and the default formatting of the retuned
date is in some collations different than in SQL Server 2000. So if you
have any queries relying on a where clause that checks a SMALLDATETIME
column you might need to adjust the date format.

Migrating to SQL 2005 might also cause some problems with character
encoding, since SQL 2005 internally works with Unicode. At least for us
who needs other characters than 7-bit ASCII... I had big trouble with
moving ISO-8859-15 XML documents to a SQL Server 2005 Unicode server and
parsing them into a native XML datatype (which is a really nice
feature!), but the problems can be overcomed with a litte extra work...

You could also check that you use the correct protocol version of
FreeTDS, if you're running PHP under Linux. I don't know how PHP
connects to MS-SQL on Windows though.

Currently I have no other thoughts of what could cause your problems, at
least without not being able to actually see the failed queries.

Regards,
Krister Karlström, Helsinki, Finland

Chris wrote:


Please always cc the mailing list so others can offer extra
advice/suggestions etc.

Weaver Hickerson wrote:

they work in query analyzer.

ok so the queries aren't the problem.

do you get an error? what is it?

Might need to play with these settings:

http://www.php.net/manual/en/function.mssql-min-error-severity.php
http://www.php.net/manual/en/function.mssql-min-message-severity.php


And they seem to work on a new server I setup for testing that has
ZendCore and on which I installed the Microsoft PHP driver and ported
the code to that driver. :(

That does seem to point to the driver, not sure what other suggestions I
can offer.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-04 Thread Weaver Hickerson
Greetings to the group.  We have a PHP4 application that we moved to SQL server 
2005 from SQL server 2000.  Everything seems to work fine except for so far we 
have found 2 queries that break.  Pointing back to the SQL Server 2000 
server, they work fine again.

Closing the gate once the horse is out, I then began googling and it appears 
that there is some controversy over whether PHP4 works with SQL 2005?   So far 
everything but this works so I'm wondering if there are some php INI settings 
and/or SQL Server settings that might make the 2 get along better..

Any help appreciated in resolving this without having to do an overnight 
forklift port to PHP5 (would that it be that easy..)



Weaver Hickerson, President
LightSpeed Technology Group
[EMAIL PROTECTED]mailto:[EMAIL PROTECTED]
770-787-0880 ext 3011


Re: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-04 Thread Chris

Weaver Hickerson wrote:

Greetings to the group.  We have a PHP4 application that we moved to SQL server 2005 from 
SQL server 2000.  Everything seems to work fine except for so far we have found 2 queries 
that break.  Pointing back to the SQL Server 2000 server, they work fine 
again.


If it's only 2 queries I suspect that sql server 2005 breaks for those 
queries (whether they added new reserved words or whatever).


If you run those 2 queries manually through the db, what happens?

--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-04 Thread Chris
Please always cc the mailing list so others can offer extra 
advice/suggestions etc.


Weaver Hickerson wrote:

they work in query analyzer.


ok so the queries aren't the problem.

do you get an error? what is it?

Might need to play with these settings:

http://www.php.net/manual/en/function.mssql-min-error-severity.php
http://www.php.net/manual/en/function.mssql-min-message-severity.php

And they seem to work on a new server I setup for testing that has 
ZendCore and on which I installed the Microsoft PHP driver and ported 
the code to that driver. :( 


That does seem to point to the driver, not sure what other suggestions I 
can offer.


--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] PHP4, mssql_* and SQL Server 2005

2008-11-04 Thread Chris

Chris wrote:
Please always cc the mailing list so others can offer extra 
advice/suggestions etc.


Weaver Hickerson wrote:

they work in query analyzer.


ok so the queries aren't the problem.

do you get an error? what is it?

Might need to play with these settings:

http://www.php.net/manual/en/function.mssql-min-error-severity.php
http://www.php.net/manual/en/function.mssql-min-message-severity.php


and possibly this one:

http://www.php.net/manual/en/function.mssql-get-last-message.php

--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php