Jump to content


oo problem


4 replies to this topic

#1 Koncept

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 14 July 2006 - 06:06 PM

wasy to tired and stressed to think can someone please help out
Error:
Fatal error: Call to undefined method waDatabase::executeQuery() in V:\xampp\htdocs\webArts\webArts\lib\db\db.php on line 75

I know what to do to fix it just remove "$db->executeQuery('SELECT * FORM test');" but thats not what i want to do i want that to actually run the executeQuery from mysqlConnection

<?php
define ('DB_BASE_DIR', dirname(__FILE__));
if(!defined('DS')){
	define('DS', DIRECTORY_SEPARATOR);
}
class waDatabase {
	function connect($info){
		$name = (isset($info['name'])) ? $info['name'] : 'default';
		$info['driver'] = strtolower($info['driver']); // For those who like CAPS...
		if(!isset($info['driver'])){ // Was there a driver provided?
			return trigger_error('No database driver specified', E_USER_ERROR);
		}
		$driver = DB_BASE_DIR . DS . 'drivers' . DS . $info['driver'] . '_driver.php';
		$class = $info['driver'] . 'Connection';
		if(!is_readable($driver)){ // Does the driver file exist?
			return trigger_error('Database driver does not exist: ' . $info['driver']  . '_driver.php', E_USER_ERROR);
		}
		require_once($driver); // Require the database driver.
		if(!class_exists($class)){ // Does the driver file contain the correct class?
			return trigger_error('Database driver does not exist: ' . $info['driver']  . '_driver.php', E_USER_ERROR);
		}
		$dbd = new $class();
		if(!is_a($dbd, 'waDbConnection')){ // Does the class extend waDbConnection?
			return trigger_error('Database driver does not extend waDbConnection: ' . $info['driver']  . '_driver.php', E_USER_ERROR);
		}
		// Error is thrown in the constructor (hopefully).
		$dbd->open($info);
	}
}
class waDbConnection {
	var $_dbinfo;
	function waDbConnection(){
		
	}
	function close(){
		assert(FALSE);
	}
	function connect($dbinfo){
		assert(FALSE);
	}
	function executeQuery($query){
		assert(FALSE);
	}
	function getRow($stmt, $args = array()){
		$result = $this->executeQuery($stmt, $args);
		$result->next();
		return $result->current();
	}
	function open($dbinfo) {
		if($ret = $this->connect($dbinfo)){
			$this->_dbinfo = $dbinfo;
			return true;
		}
	}
}

$db = new waDatabase;
$info = array(
		'driver' => 'MySQL',
		'function' => 'mysql_connect',
		'host' => 'localhost',
		'user' => 'labs',
		'password' => '965478',
		'database' => 'labs'
		);
$db->connect($info);
$db->executeQuery('SELECT * FROM test');
?>

and drivres/mysql_driver.php
<?php
class mysqlConnection extends waDbConnection{
	var $_link;
	function mysqlConnection(){
		parent::waDbConnection();
		if(!extension_loaded('mysql')){
			trigger_error('The MySQL extension is not loaded.', E_USER_ERROR);
		}
	}
	function connect($dbinfo){
		if(is_array($dbinfo)){
			switch($dbinfo['function']){
				case 'mysql_connect';
					$link = mysql_connect($dbinfo['host'], $dbinfo['user'], $dbinfo['password']) or trigger_error(mysql_error(),E_USER_ERROR);
					break;
				case 'mysql_pconnect';
					$link = mysql_pconnect($dbinfo['host'], $dbinfo['user'], $dbinfo['password']) or trigger_error(mysql_error(),E_USER_ERROR);
					break;
				default:
					trigger_error('No driver function or Invalid driver function supplied.',E_USER_ERROR);
				}
			mysql_select_db($dbinfo['database'], $link) or trigger_error(mysql_error(),E_USER_ERROR);
			$this->_link = $link;
			return true;
		}
	}
	function close(){
		$this->isConnect();
		mysql_close($this->_link);
		return true;
	}
	function executeQuery($query){
		$this->isConnect();
		mysql_query($query);
		return true;
	}
	function getInsertId() {
		return mysql_insert_id($this->_link);
	}
	function isConnect(){
		if(!$this->_link){
			trigger_error('Error: Not connected', E_USER_ERROR);
		}
		return true;
	}
}
?>

Edited by Koncept, 15 July 2006 - 12:29 AM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 14 July 2006 - 10:39 PM

Well, erm, I may sound stupid, but don't you mean to use the execute like this?

$db->executeQuery('SELECT * FROM `test`');

The rest of your class function is over my head, but I just figured that might help, since you are selecting information from the test table.

#3 Koncept

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 14 July 2006 - 10:53 PM

View PostDemonslay, on Jul 14 2006, 10:39 PM, said:

Well, erm, I may sound stupid, but don't you mean to use the execute like this?

$db->executeQuery('SELECT * FROM `test`');

The rest of your class function is over my head, but I just figured that might help, since you are selecting information from the test table.
no the problem is not my query its how im calling it =/ and i still havnt solved it but i have updated my code but still have the same problem :blush:

#4 NGPixel

    Senior Programmer

  • P2L Staff
  • PipPipPipPip
  • 1,410 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design : Coding : Animation

Posted 15 July 2006 - 12:37 AM

extend your second class in your first class header. as you cannot access the second class from simply calling it inside the first class.

class waDatabase extends waDbConnection {

#5 johndapunk

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 16 July 2006 - 03:08 PM

I was just about to mention that.^

Incase you don't understand what is wrong, you called executeQuery as if it was in your waDatabase class, but it is in your waDbConnection class.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users