Seeking help extending mysqli object

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmwmulle
Forum Newbie
Posts: 1
Joined: Sun Nov 28, 2010 8:18 am

Seeking help extending mysqli object

Post by jmwmulle »

Hi there, I've been coding with PHP for a little over a year, self-taught primarily, and I've been trying to streamline my experience a bit with some custom classes I can re-use in various projects. Currently, I'm trying to extend the mysqli object, and moreover, the mysqli_result object. Extending them, of course, isn't all that tricky. But getting the one to call the other is currently beyond me.

Basically, I'm trying to do something along the lines of this:

Here's a simple method I'd like to add so I can get my data into a purely php array a little faster.

Code: Select all

class mysqli_custom_res extends mysqli_result {
	
	function toPHP() {
		$count=$parent->num_rows;
		$data=array();
		for ($i=0; $i<$count; $i++) {
			$row=$this::fetch_assoc();
			$data[i]=$row;
		}
		return $data;
	}
}
But how could I get the mysqli object to generate a mysqli_custom_res object instead of a mysqli_result object? Any help on this would be greatly appreciated. Thanks!
Post Reply