Re: [PHP] Retrieving query from MSSQL Table
On 4/28/05, Richard Lynch [EMAIL PROTECTED] wrote: I'm betting dollars to doughnuts that you've got a newline at the end of $sql1 which is messing you up. You're right! Give that man a doughnut! When I tested the query in Query Analyzer. I hit [Enter] to format the query and make it readable, then copy-and-paste into the form. I have tried: str_replace(\n,,$sql1); and preg_replace(\n,,$sql1); to pull the new line out plus a few other variations. Those failed. I'll keep at, but any pointers are always appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving query from MSSQL Table
On Thu, April 28, 2005 5:51 am, Mike Smith said: On 4/28/05, Richard Lynch [EMAIL PROTECTED] wrote: I'm betting dollars to doughnuts that you've got a newline at the end of $sql1 which is messing you up. You're right! Give that man a doughnut! When I tested the query in Query Analyzer. I hit [Enter] to format the query and make it readable, then copy-and-paste into the form. I have tried: str_replace(\n,,$sql1); and preg_replace(\n,,$sql1); to pull the new line out plus a few other variations. Those failed. I'll keep at, but any pointers are always appreciated. If you are on a Mac, you'll have a \r in there as well. Plus, some day, you might WANT to have a newline in your data, like: UPDATE foo SET contents = War\nand\nPeace What is probably safest is: $sql1 = trim($sql1); This strips off any whitespace before/after the query, which should not affect any valid query, but will get rid of bogus newlines at the end. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving query from MSSQL Table
Thanks Richard, That did the trick. That and one query was in another database, that my users didn't have rights to...Doh! Works well. Thanks, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Retrieving query from MSSQL Table
I have a form where I can submit a Query to be run against a MSSQL 2000 Server. The query is stored correctly in a text (DataType) column. I can retrieve it echo it back to the screen, copy-n-paste into Query Analyzer and the query works. What I cannot do is get the query to be returned from the recordset and used to build a new recordset. Confused? function preview_report(){ //Get the query $s = SELECT rptsql \n; $s .= FROM rpt_mas\n; $s .= WHERE id={$_POST['frm_rptid']}\n; $r = $this-db-Execute($s); $r_arr = $r-GetArray(); $sql1 = $r_arr[0][0]; //I can echo this to the screen and run it in Query Analyzer $sql2 = SELECT id, rptname, rptdesc, rptfile, rpttype, rptsql FROM rpt_mas; if($sql!=){ $this-xq = $sql; $r = $this-db-Execute($sql1);//This doesn't work $r = $this-db-Execute($sql2);//This does work } } $sql1 $sql2 are one and the same. Any ideas what I'm missing? Thanks, Mike Smith -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieving query from MSSQL Table
On Wed, April 27, 2005 1:29 pm, Mike Smith said: I have a form where I can submit a Query to be run against a MSSQL 2000 Server. The query is stored correctly in a text (DataType) column. I can retrieve it echo it back to the screen, copy-n-paste into Query Analyzer and the query works. What I cannot do is get the query to be returned from the recordset and used to build a new recordset. Confused? function preview_report(){ //Get the query $s = SELECT rptsql \n; $s .= FROM rpt_mas\n; $s .= WHERE id={$_POST['frm_rptid']}\n; $r = $this-db-Execute($s); $r_arr = $r-GetArray(); $sql1 = $r_arr[0][0]; //I can echo this to the screen and run it in Query Analyzer $sql2 = SELECT id, rptname, rptdesc, rptfile, rpttype, rptsql FROM rpt_mas; if($sql!=){ $this-xq = $sql; if ($sql1 == $sql2){ echo They really are the same...br /\n; } else{ echo They're not REALLY the same!br /\n; for ($i = 0; $i = strlen($str1); $i++){ $c1 = $str1[$i]; $c2 = $str2[$i]; $o1 = ord($c1); $o2 = ord($c2); if ($c1 != $c2){ echo At position $i, c1 is $c1 ($o1), and c2 is $c2 ($o2)br /\n; } } } $r = $this-db-Execute($sql1);//This doesn't work echo mssql_error(); //Or whatever this should be. $r = $this-db-Execute($sql2);//This does work } } $sql1 $sql2 are one and the same. Any ideas what I'm missing? I'm betting dollars to doughnuts that you've got a newline at the end of $sql1 which is messing you up. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php