当前位置: 首页>>代码示例>>PHP>>正文


PHP Manager::setFetchMode方法代码示例

本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::setFetchMode方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::setFetchMode方法的具体用法?PHP Manager::setFetchMode怎么用?PHP Manager::setFetchMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Capsule\Manager的用法示例。


在下文中一共展示了Manager::setFetchMode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createConnection

 protected function createConnection()
 {
     $this->capsule = new Capsule();
     $this->capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/db/testing.sqlite', 'prefix' => '']);
     $this->capsule->setFetchMode(PDO::FETCH_CLASS);
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
     $this->capsule->getConnection()->enableQueryLog();
 }
开发者ID:leloulight,项目名称:trigglog,代码行数:9,代码来源:TestCase.php

示例2: register

 /**
  * Register Illuminate with the application
  *
  * @param array $config
  * @param Application $app
  * @return void
  */
 public function register(Application $app)
 {
     // Set some sane defaults
     $defaults = array('boot' => true, 'eloquent' => true, 'fetch' => PDO::FETCH_CLASS, 'global' => true, 'default' => 'default', 'connections' => array('default' => array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'silex', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null)));
     // Merge in any passed configuration
     $this->config = array_merge($defaults, $app['db.config']);
     // Make sure all connections have all required fields
     if (isset($this->config['connections'])) {
         foreach ($this->config['connections'] as $index => $connection) {
             $this->config['connections'][$index] = array_merge($defaults['connections']['default'], $connection);
         }
     }
     // Create a container for the database pool
     $app['db.container'] = $app->share(function () {
         return new Container();
     });
     // Create the connections to the datbase
     $app['db'] = $app->share(function () use($app) {
         $db = new Capsule($app['db.container']);
         // Set PDO fetch mode as per configuration
         $db->setFetchMode($this->config['fetch']);
         // Set as global, use eloquent as per configuration
         if ($this->config['eloquent']) {
             $db->bootEloquent();
         }
         if ($this->config['global']) {
             $db->setAsGlobal();
         }
         // Set up the event dispatcher if we have it available
         if (class_exists('Illuminate\\Events\\Dispatcher')) {
             $db->setEventDispatcher(new Dispatcher($app['db.container']));
         }
         // Initialise each connection
         foreach ($this->config['connections'] as $connection => $options) {
             $db->addConnection(array_replace($this->config['connections'][$this->config['default']], $options), $connection);
             // If we're in debug mode we're going to want to use the query log, otherwise leave it disabled
             // to speed up queries and reduce memory usage
             if ($app['debug']) {
                 $db->getConnection($connection)->enableQueryLog();
             }
         }
         // Finally set default connection
         $db->getDatabaseManager()->setDefaultConnection($this->config['default']);
         return $db;
     });
 }
开发者ID:sjdaws,项目名称:silluminate,代码行数:53,代码来源:DatabaseServiceProvider.php

示例3: get_root_id

<?php

use Illuminate\Database\Capsule\Manager as Capsule;
require __DIR__ . '/../comments/start.php';
// Connection to the old database.
$capsule = new Capsule();
$capsule->addConnection(require __DIR__ . '/database.php');
$capsule->setFetchMode(PDO::FETCH_OBJ);
$db = $capsule->getDatabaseManager();
// Get the comment root id for the given parent id.
function get_root_id($id)
{
    global $db;
    $comment = $db->table('comments')->where('id', $id)->first(['id', 'parent']);
    if (!$comment) {
        return $id;
    }
    if (!empty($comment->parent)) {
        return get_root_id($comment->parent);
    }
    return $comment->id;
}
// Select all comments from old table.
$comments = $db->table('comments')->get();
$status = ['pending', 'approved', 'spam'];
Comment::unguard();
// Insert the old comments into the new table.
foreach ($comments as $comment) {
    if (empty($comment->parent)) {
        $rootId = null;
    } else {
开发者ID:hazzardweb,项目名称:acs-upgrade,代码行数:31,代码来源:comments.php

示例4: Capsule

 * Database package.
 *
 * @var Illuminate\Database\Capsule\Manager
 */
$capsule = new Capsule();
/**
 * Gets the configuration from the database
 * configuration file.
 *
 * @var array
 */
$config = getconfig('database');
/**
 * Sets the PDO Fetch Mode.
 */
$capsule->setFetchMode($config['fetch']);
/**
 * Adds the configuration of the default
 * driver setting.
 */
$capsule->addConnection($config['connections'][$config['default']]);
/**
 * Set the Capsule as a global to allow
 * the usage of static methods.
 */
$capsule->setAsGlobal();
/**
 * Booting Eloquent. Enjoy.
 */
$capsule->bootEloquent();
/**
开发者ID:barticusprime,项目名称:slim-kit,代码行数:31,代码来源:database.active.php


注:本文中的Illuminate\Database\Capsule\Manager::setFetchMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。