Archive for March 23rd, 2007

Transform a MySql request to array

function requestToArray($req) 
	{
 
		$this->result_rows = 0;
		$this->result_cols = 0;
		$this->result_array = null;
		$this->error = null;
 
		$result = mysql_query($req);
 
		if (!$result) {
			$this->error = ($req . " - " . mysql_error());
			print("The request: $req didn't execute correctly: ".mysql_error()."\n");
			return null;
		}
 
		$this->result_rows = mysql_num_rows($result);
		$this->result_cols = mysql_num_fields($result);
 
		$this->result_array = array ();
		while ($tab = mysql_fetch_assoc($result)) {
			array_push($this->result_array,$tab);
		}
 
		return $this->result_array;
 
	}