Page 1 of 1

using mysqli to get Field names as an array

Posted: Sun Nov 12, 2006 1:51 pm
by mbaroz
Hi there
I have this Class (extended for mysqli )
i need to add a method(function ) that returns an array of a fieldnames associated with its index:

here is my code:(the function i was trying to implement is: getFieldName()


Code: Select all

class Sql extends mysqli {
	var $result=null;
	var $sql;
	var $record;
	var $fldName;
	function __construct($host="myhost",$user="myuser",$pwd="mypassword",$db="mydb") {
		parent::__construct($host,$user,$pwd,$db);
	}
	function doquery($sql) {
		$this->sql=$sql;
		$this->result=$this->query($sql);
		if ($this->result) return true;
		else return false;
	}
	function nextRecord() {
		$this->record=$this->result->fetch_assoc();
		if ($this->record) return true;
		else return false;
	}
	
	function getFIeld($fname) {
		$row=$this->record;
		return $row["$fname"];
	}
	function getFieldName($index) {
		$fld=$this->result->fetch_field();
		return $fld;
	}
	function NumFields() {
		$numFields=$this->result->field_count;
		return $numFields;
	}
	function NumRows() {
		$numRows=$this->result->num_rows;
		return $numRows;
	}
	
}

Thanks for help
moshe