database
| From: | alain dhaene | Date: | Mon, 27 Oct 2003 18:07:06 +0000 |
| Subject: | database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-167759@lists.php.net to get a copy of this message | ||
Hi,
I'm very new with php, so perhaps it's a silly question.
I want a connection with a mysql database.
This works. I can open, retrieve data, and close the database.
But this happens in the same page.
Now I want one page that has a function who's opening and close the
connection. In another page I want include this page. But I don't know the
syntax.
e.g
page connectie.php
Function openDB()
{
$link = mysql_connect("localhost", "host", "pas")
or die("geen connectie mogelijk : " . mysql_error());
print "connectie ok";
mysql_select_db("database") or die("geen database gevonden");
}
Function closeDB()
{
mysql_close($link);
}
End Function
?>
<?php
page input.php
include ('connectie.php');
//open connectie
$connectie = openDB();
//code
//close connectie
$connectie = closeDB();
This gives an error when I want to close the db. In the function I said
close($link) but of course he cann't see this variabel. How can I fix that?
Alain D'Haene
Or is it possible the set the connection in an Object, and use this object
during the Session?