MySQL connect function
| From: | Jack Dempsey | Date: | Wed, 18 Oct 2000 05:53:05 +0000 |
| Subject: | MySQL connect function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-20796@lists.php.net to get a copy of this message | ||
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