Hello all, I am coding a custom DBAL for my site and I am having tons of issues making it pass this one global clas variable, for some reason it keeps getting erased from memory after the first function. I have posted a section of my class that has so far been giving me the most problems. [code=php:0] class db { var $db; var $db_type; var $sql; function init($dbhost, $dbtype, $dbuser, $dbpass, $dbname) { if (!isset($dbhost)) { echo "database::init(): No database host set."; exit(); } elseif (!isset($dbtype)) { echo "database::init(): No database type set."; exit(); } elseif (!isset($dbuser)) { echo "database::init(): No database username set."; exit(); } elseif (!isset($dbpass)) { echo "database::init(): No database password set."; exit(); } elseif (!isset($dbname)) { echo "database::init(): No database name set."; exit(); } switch ($dbtype) { case "mysql": $mysql_connect = @mysql_connect($dbhost, $dbuser, $dbpass); $mysql_select_db = @mysql_select_db($dbname); if ((!$mysql_connect) || (!$mysql_select_db)) { echo "database::init(): Database Error:<br>" . mysql_error(); exit(); } $this->db_type = $dbtype; break; case "postgresql": $this->db = @pg_connect("host={$dbhost} dbname={$dbname} user={$dbuser} pass={$dbpass}"); if (!$this->db) { echo "database::init(): Database Error:<br>" . pg_last_error($this->db); exit(); } $this->db_type = $dbtype; break; case "sqlite": $this->db = @sqlite_open($dbname); if (!$this->db) { echo "database::init(): Database Error:<br>" . sqlite_error_string(sqlite_last_error($this->db)); exit(); } $this->db_type = $dbtype; break; default: echo "database::init(): No database type set."; exit(); break; } } function query($sql) { if (!isset($sql)) { echo "database::query(): No SQL code set."; exit(); } elseif (!isset($this->db_type)) { echo "database::query(): No database type set."; exit(); } if (is_array($sql)) { foreach ($sql as $key => $value) { switch ($this->type) { case "mysql": $this->sql['$key'] = mysql_query($value); if (!$this->sql['$key']) { echo "database::query(): Database Error:<br>" . mysql_error(); exit(); } return $this->sql['$key']; break; case "postgresql": $this->sql['$key'] = pg_query($this->db, $value); if (!$this->sql['$key']) { echo "database::query(): Database Error:<br>" . pg_result_error($this->db); exit(); } return $this->sql['$key']; break; case "sqlite": $this->sql['$key'] = sqlite_query($this->db, $value); if (!$this->sql['$key']) { echo "database::query(): Database Error:<br>" . sqlite_error_string(sqlite_last_error($this->db)); exit(); } return $this->sql['$key']; break; } } } else { switch ($this->db_type) { case "mysql": $this->sql = mysql_query($sql); if (!$this->sql) { echo "database::query(): Database Error:<br>" . mysql_error(); exit(); } return $this->sql; break; case "postgresql": $this->sql = pg_query($this->db, $sql); if (!$this->sql) { echo "database::query(): Database Error:<br>" . pg_result_error($this->db); exit(); } return $this->sql; break; case "sqlite": $this->sql = sqlite_query($this->db, $sql); if (!$this->sql) { echo "database::query(): Database Error:<br>" . sqlite_error_string(sqlite_last_error($this->db)); exit(); } return $this->sql; break; } } } [/code] When I call function init(), its supposed to connect to the database according to which database system I am using from the $dbtype parameter. Then I take $dbtype and put it into the global class variable $this->db_type, and this is the part that just doesn't make ANY sense. When I go and call the function query(), I get an error message from my error checking system in each function that says, no database type was set, and I do some tests like try to echo each variable and stuff. $this->db_type works in init() but it seems to be cleared when used in query() and there isnt any data in the variable when I try to use it in another function. Now, I dont know but this problem most likely also applies to all the other functions in my class. Can someone PLEASE help!? Thanks alot! -maddog39