Jump to content

Need help with a function


fert

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.