Re: MySQL connect function
| From: | David Robley | Date: | Wed, 18 Oct 2000 08:25:36 +0000 |
| Subject: | Re: MySQL connect function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20842@lists.php.net to get a copy of this message | ||
On Wed, 18 Oct 2000, Jack Dempsey wrote:
> Hi all
>
> I know this is a somewhat lazy request, but here's my situation:
>
> I have multiple files in which i need to connect to a MySQL database.
> Instead of typing out the connection each time for each file, I want to just
> create a connect.php file that says:
>
> <?PHP
>
> function connect($sql){
>
> [i'll leave out syntax, but yes, it works fine when NOT being included]
>
> }
> ?>
>
> then in the files i need to connect, i'd like to say:
>
> require "connect.php";
>
> $sql_result = connect($sql);
>
> then later on i call the $sql_result:
>
> while ($row = mysql_fetch_array($sql_result)){
>
> and get an error.....now, i didn't think it mattered that i used
> mysql_fetch_array after i've already closed the connection in the included
> file, because i still have the result.....yet i received an error......
> is this technique just plain stupid, can it work, or does anyone have a
> suggestion to easily accomplish a similar thing?
> Much thanks!
> Jack Dempsey
Once you have closed the connection, you no longer have access to the
result set which is pointed to by $sql_result. Either keep the connection
open, or stick all your results in an array which the function would then
return.
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA