fert Posted March 24, 2007 Share Posted March 24, 2007 I have this class class db { var $type; var $host; var $username; var $password; var $db_name; var $cn; var $result; function db() { eeggs(); $db=parse_ini_file("../config/db.ini"); $this->type=$db['database_type']; $this->host=$db['host']; $this->username=$db['username']; $this->password=$db['password']; $this->db_name=$db['db_name']; if($this->type=="mysql") { $this->cn=@mysql_connect($this->host,$this->username,$this->password) or die(mysql_error()); @mysql_select_db($this->db_name,$this->cn) or die(mysql_error()); } else if($this->type=="postgre") { if(function_exists("pg_connect")) { $this->cn=pg_connect("host={$this->host} user={$this->username} password={$this->password} dbname={$this->db_name}"); } } } function query($sql) { if($this->db_type=="mysql") { $this->result=@mysql_query($sql,$this->cn) or die(mysql_error()); } else if($this->db_type=="postgre") { if(function_exists("pg_connect")) { $this->result=pg_query($sql,$this->cn); } } return $this->result; } function fetch_array($result) { if($this->db_type=="mysql") { return mysql_fetch_array($result); } else { if(function_exists("pg_connect")) { return pg_fetch_array($result); } } } function num_rows($result) { if($this->db_type=="mysql") { return mysql_num_rows($result); } else { if(function_exists("pg_connect")) { return pg_num_rows($result); } } } } This problem with this code is that the fetch_array function doesn't return an array like I want it to, it returns an object Quote Link to comment Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 I believe this: if($this->db_type=="mysql") Should be: if($this->type=="mysql") You need to fix that in a few places. Orio. Quote Link to comment Share on other sites More sharing options...
fert Posted March 24, 2007 Author Share Posted March 24, 2007 I fixed that, but it still does the same thing Quote Link to comment Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 Try: if(strtolower($this->type) == "mysql") Orio. Quote Link to comment Share on other sites More sharing options...
fert Posted March 24, 2007 Author Share Posted March 24, 2007 nope, still the same problem Quote Link to comment Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 Are you sure that "database_type" is defined in config/db.ini? Orio. Quote Link to comment Share on other sites More sharing options...
fert Posted March 24, 2007 Author Share Posted March 24, 2007 yes, I'm sure Quote Link to comment Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 Let's see to what parts it enters... Change the function to this, and tell what output you're getting: <?php function fetch_array($result) { if($this->db_type=="mysql") { echo "in mysql"; return mysql_fetch_array($result); } else { echo "in else<br>"; if(function_exists("pg_connect")) { echo "in pg"; return pg_fetch_array($result); } } } ?> Orio. Quote Link to comment Share on other sites More sharing options...
fert Posted March 24, 2007 Author Share Posted March 24, 2007 It's telling me "in mysql" (as it should), but i'm still getting the same error Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.