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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.