I cannot access the raw PDO instance in Laravel 5

后端 未结 2 1822
栀梦
栀梦 2021-01-23 13:22

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::

相关标签:
2条回答
  • 2021-01-23 13:45
    $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
    
    }
    
    0 讨论(0)
  • 2021-01-23 13:46

    You need either to reference it as \DB or add a use DB; at the top of your controller.

    0 讨论(0)
提交回复
热议问题