2

I would like to implement my own database dialect in Phalcon PHP. I would like to extend and override few functions that are already reserved for PDO. This is what I'm trying to do:

class DB extends \Phalcon\Db\Adapter\Pdo\Mysql{
    function _construct($connection_variables=array())
    {
        parent::_construct($connection_variables);
    }

    function update($table="",$variables="")
    {
        parent::execute($query);
    }
}

So, when I try to to call in the model:

$this->db->update('test',array('id'=>'1'));

It gives me an error stating that:

Fatal error: Declaration of Libraries\DB::update() must be compatible with Phalcon\Db\AdapterInterface::update($table, $fields, $values, $whereCondition = NULL, $dataTypes = NULL) in ..... 

How can I override update and insert functions? Thanks

1 Answer 1

2

Your update method must match with the method declared in the Phalcon\Db\AdapterInterface interface, it should be:

function update($table, $fields, $values, $whereCondition = NULL, $dataTypes = NULL)
{
    // ...
}

Instead of:

function update($table="",$variables="")
{
    // ...
}

The method signature/header must be the same as it is in the interface.

Sign up to request clarification or add additional context in comments.

4 Comments

But I want to have a custom update function. In Phalcon, for some reason you need to have fields in array separate from values - which is not pretty. I want to pass values as associative array ('field1'=>'value1','field2'=>'value2'), like in CodeIgniter. Is there a way to do that by extending the class?
In this case you can't use same method with a different signature, you must use same method declaration or otherwise use a different one.
Thank you! It seems I will need to be creative with the method naming.
Well, this is the nature of an interface, you are welcome :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.