it got too annoying throwing exceptions line by line using mysqli, so now i'm trying to wrap up all my mysqli functions so that it throws real exceptions base on the Exception class.

Right now, mysqli's stmt bind_param method can't seem to return its error message no matter what i tried. What's going on?

customized stmt class :

class ext_mysqli_stmt extends mysqli_stmt {

public function bind_param($types, $arr){
	if(@!parent::bind_param($types, $arr)){
		throw new Exception($this->error);
	}
}

}

customized mysqli class :

	public function prepare($query){

	$stmt = new ext_mysqli_stmt($this, $query);
	if(!$stmt) throw new Exception(mysqli_connect_error()." $query");

	return $stmt;
}

I tried using mysqli_stmt_error($this) on the stmt class, it didn't work either. The message thrown was just an empty string.

Whereas the error messages appear when i capture them from
set_error_handler.

The error i tried was passing unknown data type such as :

//$mysqli is an instance of ext_mysqli

$stmt = $mysqli->prepare($query);

$stmt->bind_param("3i", $para1, $para2, $para3);

    Have you considered using the PDO extension with PDO::ERRMODE_EXCEPTION?

      i haven't read up on PDO though, is it going to be easy to extend it ? It's supposed to be some sort of database abstraction layer rite?

      i'll look at it if this is the case.

        It's supposed to be some sort of database abstraction layer rite?

        It is more of a uniform PHP interface than a database abstraction layer.

        i haven't read up on PDO though, is it going to be easy to extend it ?

        My point is that it already has the feature that you are trying to implement via inheritance, i.e., it can be configured to throw exceptions.

          Write a Reply...