1
votes

I have a Sphinx search engine running on MySQL protocol and I use Phalcon\Db\Adapter\Pdo\Mysql to connect to it. Sphinx tables are implemented as models.

When I try to select (using SpinxQL) I, obviously, get an error when database adapter attempts to extract table metadata running queries against tables which are not supported and not present respectively in SpinxQL. There is a workaround in the documentation showing how to manually assign metadata... But being to lazy by nature I want to try to automate metadata generation.

I assume that metadata is produced by the database adapter, probably as a result of calling getColumnsList() on the instance following getColumnDefinition() or something else (???). Is this my assumption correct? I want is to extend Phalcon\Db\Adapter\Pdo\Mysql and override those methods to be compatible with Sphinx.

Thanks in advance for your suggestions!

1

1 Answers

2
votes

Ok, you need to override at least two methods to make this work, the following class would work:

<?php

class SphinxQlAdapter extends Phalcon\Db\Adapter\Pdo\Mysql implements Phalcon\Db\AdapterInterface
{

    /**
     * This method checks if a table exists
     *
     * @param string $table
     * @param string $schema
     * @return boolean
     */
    public function tableExists($table, $schema=null)
    {

    }

    /**
     * This method describe the table's columns returning an array of
     * Phalcon\Db\Column
     *
     * @param string $table
     * @param string $schema
     * @return Phalcon\Db\ColumnInterface[]
     */
    public function describeColumns($table, $schema=null)
    {

    }

}

Then in your connection, you use the new adapter:

$di->set('db', function(){
    return new SphinxQlAdapter(
        //...
    );
});