All pastes #832143 Raw Edit

Mine

public php v1 · immutable
#832143 ·published 2007-12-25 21:10 UTC
rendered paste body
public function query()	{			if(!($nargs = func_num_args()))			throw new DBException("Not enough arguments for query.");				$args = func_get_args();		$query = array_splice($args, 0, 1);				$stmt = $this->mysqli->prepare($query[0]); // Prepare query				// I wonder if this'll really benefit performance this way...		if($nargs != 1)		{			$typelist = '';			foreach($args as $arg)			{				if(is_float($arg)) // Float					$typelist .= 'd';				elseif(is_int($arg) && count($arg) > 16) // Blob or bigint					$typelist .= 'b';				elseif(is_int($arg)) // Int					$typelist .= 'i';				elseif(is_string($arg) || is_bool($arg)) // String or bool					$typelist .= 's';			}						$nargs = array();			for($i = 0; $i != count($args); $i++)				$nargs[] = '$args['.$i.']';						eval('$stmt->bind_param("'.$typelist.'", '.implode(", ", $nargs).');');		}				if(!$stmt->execute())			throw new DBException($stmt->error(), $stmt->errno);				$stmt->store_result();				// If there are any fields to return, return a mysqli_result object		if(($fcount = $stmt->field_count))		{			$toeval = "";			$arr = array();			$mt = $stmt->result_metadata();			$fields = $mt->fetch_fields();			foreach($fields as $field)				$toeval .= '$arr['.($field->name).'], ';			$toeval = substr($toeval, 0, strlen($toeval)-2);			eval('$stmt->bind_result('.$toeval.');');						$result = array();			$i = 0;			while($stmt->fetch())			{				foreach($arr as $name => $value)					$result[$i][$name] = $value;				$i++;			}						return $result;		}				return true;	}