Re: [PHP] Returning a Recordset from a Funtion

2010-06-25 Thread Richard Quadling
On 25 June 2010 14:55, David Stoltz dsto...@shh.org wrote:
 ?php

 include('../includes/mssql.php');

 hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?

You are not catching the result of the hitMSSQL() function.

Try ...

?php

include('../includes/mssql.php');

$rs = hitMSSQL(server,database,username,password,SELECT * FROM
TABLE1);

echo $rs-Fields(1);

?


-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



RE: [PHP] Returning a Recordset from a Funtion

2010-06-25 Thread David Stoltz
Tried that - 

I finally got it - in the function I had to return the actual query execute, 
instead of the recordset.

This did not work:

$rs = $conn-execute($query);
Return $rs;

This DID work:

Return $conn-execute($query);

Thanks for the reply!

-Original Message-
From: Richard Quadling [mailto:rquadl...@gmail.com] 
Sent: Friday, June 25, 2010 9:59 AM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] Returning a Recordset from a Funtion

On 25 June 2010 14:55, David Stoltz dsto...@shh.org wrote:
 ?php

 include('../includes/mssql.php');

 hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?

You are not catching the result of the hitMSSQL() function.

Try ...

?php

include('../includes/mssql.php');

$rs = hitMSSQL(server,database,username,password,SELECT * FROM
TABLE1);

echo $rs-Fields(1);

?


-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


Re: [PHP] Returning a Recordset from a Funtion

2010-06-25 Thread Richard Quadling
On 25 June 2010 15:07, David Stoltz dsto...@shh.org wrote:
 Tried that -

 I finally got it - in the function I had to return the actual query execute, 
 instead of the recordset.

 This did not work:

 $rs = $conn-execute($query);
 Return $rs;

 This DID work:

 Return $conn-execute($query);

 Thanks for the reply!

 -Original Message-
 From: Richard Quadling [mailto:rquadl...@gmail.com]
 Sent: Friday, June 25, 2010 9:59 AM
 To: David Stoltz
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Returning a Recordset from a Funtion

 On 25 June 2010 14:55, David Stoltz dsto...@shh.org wrote:
 ?php

 include('../includes/mssql.php');

 hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?

 You are not catching the result of the hitMSSQL() function.

 Try ...

 ?php

 include('../includes/mssql.php');

 $rs = hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?


 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling



Can you ...

var_dump($rs);

in the function?

I'd be very surprised that ...

return $rs;

with

$rs = your_func();

didn't work.


So much so, I'm guessing you are not showing the whole story somewhere.



Pretty much without exception,

   $rs = $conn-execute($query);

   return $rs;

is the same as ...

   return $conn-execute($query);


Richard.
-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Returning a Recordset from a Funtion

2010-06-25 Thread Andrew Ballard
On Fri, Jun 25, 2010 at 9:55 AM, David Stoltz dsto...@shh.org wrote:
 Hi Folks,



 Upon occasion, I have the need to hit our MS MSL database from our
 PHP/mySQL server. So I've created a function, but I'm not sure if you
 can return a recordset from a function. My code is below...



 In the calling page I code:

 ?php

 include('../includes/mssql.php');

 hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?



 The mssql.php include file is:

 ?php

 function hitMSSQL($server,$db,$login,$pass,$query){



                $conn = new COM (ADODB.Connection)

                  or die(Cannot start ADO);

                $connStr =
 PROVIDER=SQLOLEDB;SERVER=.$server.,1433;UID=.$login.;PWD=.$pass.;
 DATABASE=.$db;

                $conn-open($connStr);

                $rs = $conn-execute($query);

                return $rs;



 }

 ?



 If I have the echo statement in the function, it works.



 And of course I can return a single value like:

 Return $rs-Fields(value);



 But I can't return the whole recordset...



 Does anyone have any good ideas so I can access the recordset in the
 calling page?



 Thanks!



Is there a reason you need to work with COM/ADODB to get the
information from SQL Server as opposed to one of the PHP libraries? If
your are using COM you must be running under Windows which means you
should be able to use Microsoft's SQL Server Driver for PHP, which is
the best tool I've seen to date for the task. There are also the older
mssql and the newer PDO_MSSQL libraries, or even odbc or PDO_ODBC that
will work OK in many cases as well. Any of these are much simpler to
work with than COM variants in PHP.

Andrew

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



RE: [PHP] Returning a Recordset from a Funtion

2010-06-25 Thread David Stoltz
The only reasons are I'm a PHP newbie ;-)

I'm not really familiar with all the ways to hit a MS SQL server, this 
particular way always worked for me. It's not difficult to code, and has been 
working for years, so I've grown accustom to it.

There are only a few instances left to connect to MS MSQL for me, so it's not 
used too often - we're now developing with mySQL.

Thanks for the info.


-Original Message-
From: Andrew Ballard [mailto:aball...@gmail.com] 
Sent: Friday, June 25, 2010 10:38 AM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] Returning a Recordset from a Funtion

On Fri, Jun 25, 2010 at 9:55 AM, David Stoltz dsto...@shh.org wrote:
 Hi Folks,



 Upon occasion, I have the need to hit our MS MSL database from our
 PHP/mySQL server. So I've created a function, but I'm not sure if you
 can return a recordset from a function. My code is below...



 In the calling page I code:

 ?php

 include('../includes/mssql.php');

 hitMSSQL(server,database,username,password,SELECT * FROM
 TABLE1);

 echo $rs-Fields(1);

 ?



 The mssql.php include file is:

 ?php

 function hitMSSQL($server,$db,$login,$pass,$query){



                $conn = new COM (ADODB.Connection)

                  or die(Cannot start ADO);

                $connStr =
 PROVIDER=SQLOLEDB;SERVER=.$server.,1433;UID=.$login.;PWD=.$pass.;
 DATABASE=.$db;

                $conn-open($connStr);

                $rs = $conn-execute($query);

                return $rs;



 }

 ?



 If I have the echo statement in the function, it works.



 And of course I can return a single value like:

 Return $rs-Fields(value);



 But I can't return the whole recordset...



 Does anyone have any good ideas so I can access the recordset in the
 calling page?



 Thanks!



Is there a reason you need to work with COM/ADODB to get the
information from SQL Server as opposed to one of the PHP libraries? If
your are using COM you must be running under Windows which means you
should be able to use Microsoft's SQL Server Driver for PHP, which is
the best tool I've seen to date for the task. There are also the older
mssql and the newer PDO_MSSQL libraries, or even odbc or PDO_ODBC that
will work OK in many cases as well. Any of these are much simpler to
work with than COM variants in PHP.

Andrew