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 Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/ 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. Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214110 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 Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214112 Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 Try: if(strtolower($this->type) == "mysql") Orio. Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214113 Share on other sites More sharing options...
fert Posted March 24, 2007 Author Share Posted March 24, 2007 nope, still the same problem Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214114 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. Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214120 Share on other sites More sharing options...
fert Posted March 24, 2007 Author Share Posted March 24, 2007 yes, I'm sure Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214125 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. Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214131 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 Link to comment https://forums.phpfreaks.com/topic/44097-need-help-with-a-function/#findComment-214319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.