Newbie question about classes and databases...

From: Date: Thu, 02 Mar 2000 18:22:25 +0000
Subject: Newbie question about classes and databases...
Groups: php.version4 
Request: Send a blank email to php-version4+get-11372@lists.php.net to get a copy of this message
Hello, I'm trying to create a class to encapsulate most of my database functionality. Everything works just fine until I execute a query in the class. The first time I execute a query, everything seems to work fine. The second time I get a message saying that the class cannot be redeclared. Do I need to explicitly destroy the class object or is there some weird class/database/caching interaction going on? Below is a copy of the code I'm executing and a copy of the database connection class. Note that if I don't call the Query method, everything works just fine. Do I need to do something special to delete query objects? Any help would be greatly appreciated. Here is the code: // This is the page I am executing <? require("application_db.php"); ?> <html> <head> <title>Untitled</title> </head> <body> <? $TheQuery = "SELECT * FROM KB_Article_Author WHERE Author_Active=1"; echo( $TheQuery ); $TheConnection = new Connection; $TheConnection->Connect("devsupp", "dev_supp", "password"); $TheConnection->Query($TheQuery); $TheConnection->Close(); ?> </body> </html> // This is all placed in a file called application_db.php <? class Connection { var $v_connect; // The connection id var $v_cursor; // The cursor id function Connection() { $this->v_connect = 0; $this->v_cursor = 0; } function IsConnected() { return $this->v_connect != 0; } function StartTransaction() { if ($this->IsConnected()) return odbc_autocommit( $this->v_connect, false ); else return -100; // no connection } function CommitTransaction() { if ($this->IsConnected()) return odbc_commit( $this->v_connect ); else return -100; // no connection } function RollbackTransaction() { if ($this->IsConnected()) return odbc_rollback( $this->v_connect ); else return -100; // no connection } function EndTransaction() { if ($this->IsConnected()) return odbc_autocommit( $this->v_connect, true ); else return -100; // no connection } function Connect($DSN_NAME, $DSN_USER, $DSN_PASS) { if ( !$this->IsConnected() ) { $this->v_connect = odbc_connect( $DSN_NAME , $DSN_USER, $DSN_PASS ); if (!$this->v_connect) odbc_close(); return $this->v_connect; } else return -101; // already connected } function Query($QUERY) { if ($this->IsConnected()) { $this->v_cursor = odbc_exec( $this->v_connect, $QUERY ); return $this->v_cursor; } else return -100; // no connection } function LoadRow() { if ($this->v_cursor) return odbc_fetch_row( $this->v_cursor ); else return -200; // no Cursor } function FetchColumn( $NAME ) { if ($this->v_cursor) return odbc_result( $this->v_cursor, $NAME ); else return -200; // no Cursor } function NumRows() { if ($this-v_cursor) return odbc_num_rows( $this->v_cursor ); else return -200; // no cursor } function Close() { if ($this->IsConnected()) { odbc_close( $this->v_connect ); $this->v_connect = 0; $this->v_cursor = 0; } } } ?> -- Ryan Robertson Palm Development Support

« previous php.version4 (#11372) next »