我无法访问Laravel 5中的原始PDO实例 [英] I cannot access the raw PDO instance in Laravel 5
本文介绍了我无法访问Laravel 5中的原始PDO实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是laravel的新手,我正在尝试访问原始PDO实例,引用此文档DB::connection()->getPdo();到我的控制器,即可访问nofollow> http://laravel.com/docs/5.0/database#accessing-connections .但我收到此错误:
I'm new to laravel and I'm trying to access the raw PDO instance referring to this doc http://laravel.com/docs/5.0/database#accessing-connections by using this code DB::connection()->getPdo();
to my controller. But I'm getting this error:
FatalErrorException in GeneralCategoryController.php line 24:
Class 'App\Http\Controllers\DB' not found
我已经尝试包含此命名空间Illuminate\Support\Facades\DB
,但仍然没有结果.
请注意,我已经连接到mysql数据库.
我想念什么吗?
I've already tried to include this namespace Illuminate\Support\Facades\DB
but still no result.
Please note that I'm connected already to mysql database.
Am I missing something?
推荐答案
$pdo = DB::connection()->getPdo();
$query=$pdo->prepare("SHOW TABLES");
$query->execute();//$query->execute(array($bindings ));
while($row=$query->fetch(\PDO::FETCH_BOTH)) {
//Use \PDO::FETCH_ASSOC, \PDO::FETCH_OBJ
//echo $row->yourcolumnname;//its an object when \PDO::FETCH_OBJ
echo $row[0]; //Indexed Array
}
这篇关于我无法访问Laravel 5中的原始PDO实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文