如何调试在CodeIgniter中执行的雄辩查询



我正在使用雄辩5。

在谷歌搜索后,我使用雄辩的orm在codeigniter内部使用添加的查询日志记录并启用了ci profiler,我看到了"无查询执行",

我的database.php配置雄辩的外观如下

//Eloquent ORM database connection
use IlluminateDatabaseCapsuleManager as Capsule;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
 'dsn' => 'mysql:host=localhost; dbname=communit_iwa_test charset=utf8;',
'host' => $db['default']['hostname'],
'database' => $db['default']['database'],
'username' => $db['default']['username'],
'password' => $db['default']['password'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => $db['default']['dbprefix'],
));
$capsule->setAsGlobal();  
$capsule->bootEloquent();

$events = new IlluminateEventsDispatcher;
$events->listen('illuminate.query',function($query, $bindings, $time,$name) {
// Format binding data for sql insertion
foreach ($bindings as $i => $binding) {
    if ($binding instanceof DateTime) {
        $bindings[$i] = $binding->format(''Y-m-d H:i:s'');
    } else if (is_string($binding)) {
        $bindings[$i] = "'$binding'";
    }
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
// Add it into CodeIgniter
$db = & get_instance()->db;
$db->query_times[] = $time;
$db->queries[] = $query;
});
$capsule->setEventDispatcher($events);
/* End of file database.php */
/* Location: ./application/config/database.php */

提前赞赏您的帮助

查看执行的雄辩查询使用getQueryLog()IlluminateDatabaseCapsuleManager;

的方法

简短

  1. 在您的控制器或模型中以use IlluminateDatabaseCapsuleManager as Capsule;
  2. IlluminateDatabaseCapsuleManager类包括在内
  3. 使用 Capsule::getQueryLog()方法查看eloquent orm中执行的所有查询的数组

相关内容

  • 没有找到相关文章

最新更新