0

I'm trying to do a class to connect to the database using mysqli, from this class, I inherit other class who call a method to do a query. Here part of the class:

    protected $conn;
    protected $stmt;
    protected $reflection; 
    protected $sql;

    public function connect() {
        $this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    }

    protected function prepare_query() {
        $this->stmt = $this->conn->prepare($this->sql);
        $this->reflection = new ReflectionClass('mysqli_stmt');
    }

    protected function set_params() {
        $method = $this->reflection->getMethod('bind_param');
        $method->invokeArgs($this->stmt, $this->data);
    }

    public function execute() {
        $this->connect();
        $this->prepare_query();
        $this->set_params();
        $this->stmt->execute();
    }

I send the array with the arguments, without problem. But... then I get this error: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given I can see when I use the debugger, the array is ok, the query is ok. So, what I'm doing wrong?

Greetings from CO

KESO
  • 335
  • 2
  • 5
  • 17
  • Not your question, but what's the point of using reflection here? – Supericy Jan 05 '13 at 00:30
  • To achieve a generic abstraction layer – KESO Jan 05 '13 at 00:32
  • It looks like you're trying to un-stupid mysqli binding. I don't blame you. Have you considered just using PDO instead? The way it does binding isn't stupid by default. – Charles Jan 05 '13 at 00:34
  • Ok, is based on an example that I read, but I modified methods and properties (before they were as static). Can you suggest a better guide? – KESO Jan 05 '13 at 00:40

0 Answers0