Re: Class for database-access doesn't work
| From: | John Lim | Date: | Sun, 11 Nov 2001 11:33:13 +0000 |
| Subject: | Re: Class for database-access doesn't work | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74165@lists.php.net to get a copy of this message | ||
Leave out the second $.
Eg, $this->database is correct.
Next time when debugging, set error_reporting(E_ALL);
This will catch this error I believe.
Bye, John
Alexander Czernay <alexander@czernay.com> wrote in message
news:20011111004055.84799.qmail@pb1.pair.com...
> Hi,
>
> I just tried to write a simple class for opening a MySQL-database with
PHP.
> The database get's opened, but the handle isn't transfered back. I can
then
> use the database, but only if I don't specify the handle in mysql_query.
>
> Any ideas?
>
> Code:
> db.php:
> <?
> class Database {
> var $connect;
> var $database;
>
> function Database($host="local") {
> switch ($host) {
> case "local" :
> $this->$connect = mySQL_connect("host","user","pass");
> $this->$database = mysql_select_db("db", $this->$connect);
> break;
> }
> }
>
> function getConnect() {
> return $this->$connect;
> }
>
> function getDatabase() {
> return $this->$database;
> }
> }
> ?>
>
> test.php:
> <html>
> <head>
> </head>
>
> <body>
>
> <?
> include("lib/db.php");
>
> $db = new Database();
> $connect = $db->$getConnect;
>
> $result = mysql_query("select * from data");
> while ($data = mysql_fetch_array($result)) {
> extract($data);
> echo "-".$id."-<br>";
> }
>
>
> ?>
>
> </body>
> </html>
>
>
>