我有一个运行在MySQL协议上的Sphinx搜索引擎,我使用连接到它。Sphinx表被实现为模型。
当我尝试选择(使用SpinxQL)时,很明显,当数据库适配器尝试提取表元数据时,对SpinxQL中分别不支持和不存在的表运行查询时,会出现错误。文档中有一个解决方法,显示了如何手动分配元数据...但是,由于我天生懒惰,所以我想尝试自动生成元数据。
我假设元数据是由数据库适配器生成的,可能是因为在getColumnDefinition()或其他(?)之后的实例上调用了getColumnsList()。这是我的假设吗?我想要的是扩展Phalcon\Db\Adapter\Pdo\Mysql并覆盖那些与Sphinx兼容的方法。
提前感谢您的建议!
发布于 2012-12-11 02:13:21
好的,你需要覆盖至少两个方法才能让它工作,下面的类就可以工作了:
<?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)
{
}
}然后,在您的连接中,使用新适配器:
$di->set('db', function(){
return new SphinxQlAdapter(
//...
);
});https://stackoverflow.com/questions/13786532
复制相似问题