本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::connection方法的具体用法?PHP Manager::connection怎么用?PHP Manager::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Capsule\Manager
的用法示例。
在下文中一共展示了Manager::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Register the Capsule service.
*
* @param Application $app
**/
public function register(Application $app)
{
$app['capsule.connection_defaults'] = array('driver' => 'mysql', 'host' => 'localhost', 'database' => null, 'username' => 'root', 'password' => null, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null, 'logging' => false);
$app['capsule.global'] = true;
$app['capsule.eloquent'] = true;
$app['capsule.container'] = $app->share(function () {
return new Container();
});
$app['capsule.dispatcher'] = $app->share(function () use($app) {
return new Dispatcher($app['capsule.container']);
});
if (class_exists('Illuminate\\Cache\\CacheManager')) {
$app['capsule.cache_manager'] = $app->share(function () use($app) {
return new CacheManager($app['capsule.container']);
});
}
$app['capsule'] = $app->share(function ($name) use($app) {
$capsule = new Capsule($app['capsule.container']);
$capsule->setEventDispatcher($app['capsule.dispatcher']);
if (isset($app['capsule.cache_manager']) && isset($app['capsule.cache'])) {
$capsule->setCacheManager($app['capsule.cache_manager']);
foreach ($app['capsule.cache'] as $key => $value) {
$app['capsule.container']->offsetGet('config')->offsetSet('cache.' . $key, $value);
}
}
if ($app['capsule.global']) {
$capsule->setAsGlobal();
}
if ($app['capsule.eloquent']) {
$capsule->bootEloquent();
}
if (!isset($app['capsule.connections'])) {
$app['capsule.connections'] = array('default' => isset($app['capsule.connection']) ? $app['capsule.connection'] : array());
}
foreach ($app['capsule.connections'] as $connection => $options) {
$options = array_replace($app['capsule.connection_defaults'], $options);
$logging = $options['logging'];
unset($options['logging']);
$capsule->addConnection($options, $connection);
if ($logging) {
$capsule->connection($connection)->enableQueryLog();
} else {
$capsule->connection($connection)->disableQueryLog();
}
}
return $capsule;
});
}
示例2: queryBuilder
/**
* For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id.
*/
public static function queryBuilder()
{
// Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects)
Capsule::connection()->setFetchMode(\PDO::FETCH_ASSOC);
$table = Database::getSchemaTable(static::$_table_id)->name;
return Capsule::table($table);
}
示例3: __construct
public function __construct()
{
$this->addCollector(new MessagesCollector());
$this->addCollector(new RequestDataCollector());
$this->addCollector(new TimeDataCollector());
$this->addCollector(new RouteDataCollector());
$this->addCollector(new ExceptionsCollector());
$values = \Parameters::get('redis');
$redis_enable = isset($values['default']['enable']) ? $values['default']['enable'] : 0;
if ($redis_enable != 0) {
$this->addCollector(new RedisDataCollector());
}
try {
$conn = Capsule::connection("default");
if ($conn != null) {
$db = $conn->getPdo();
$pdo = new TraceablePDO($db);
$this->addCollector(new PDOCollector($pdo));
}
} catch (\Illuminate\Contracts\Container\BindingResolutionException $ex) {
$this['exceptions']->addException($ex);
} catch (\PDOException $e) {
$this['exceptions']->addException($e);
}
}
示例4: setUp
protected function setUp()
{
$schema_sql = file_get_contents(TEST_SCHEMA_SQL);
\Illuminate\Database\Capsule\Manager::connection()->getPdo()->exec($schema_sql);
$createQuestion0 = new M_Question();
$createQuestion0->createQuestion('タイトル0', '問題文00', '選択肢01', '選択肢02', '選択肢03', '選択肢04', 4);
$createQuestion00 = new M_Question();
$createQuestion00->createQuestion('タイトル00', '問題文00', '選択肢10', '選択肢20', '選択肢30', '選択肢40', 3);
$createQuestion000 = new M_Question();
$createQuestion000->createQuestion('タイトル000', '問題文000', '選択肢100', '選択肢200', '選択肢300', '選択肢400', 3);
$createQuestion0000 = new M_Question();
$createQuestion0000->createQuestion('タイトル0000', '問題文0000', '選択肢1000', '選択肢2000', '選択肢3000', '選択肢4000', 3);
$createQuestion00000 = new M_Question();
$createQuestion00000->createQuestion('タイトル00000', '問題文00000', '選択肢10000', '選択肢20000', '選択肢30000', '選択肢40000', 3);
$createQuestion000000 = new M_Question();
$createQuestion000000->createQuestion('タイトル000000', '問題文00000000', '選択肢10000000', '選択肢20000000', '選択肢30000000', '選択肢40000000', 3);
$createQuestion0000000 = new M_Question();
$createQuestion0000000->createQuestion('タイトル0000000', '問題文0000000', '選択肢1000000', '選択肢2000000', '選択肢3000000', '選択肢4000000', 3);
$createQuestion00000000 = new M_Question();
$createQuestion00000000->createQuestion('タイトル00000000', '問題文00000000', '選択肢10000000', '選択肢20000000', '選択肢30000000', '選択肢40000000', 3);
$createQuestion000000000 = new M_Question();
$createQuestion000000000->createQuestion('タイトル000000000', '問題文000000000', '選択肢100000000', '選択肢200000000', '選択肢300000000', '選択肢400000000', 3);
$createQuestion0000000000 = new M_Question();
$createQuestion0000000000->createQuestion('タイトル0000000000', '問題文0000000000', '選択肢1000000000', '選択肢2000000000', '選択肢3000000000', '選択肢4000000000', 3);
$createQuestion999 = new M_Question();
$createQuestion999->createQuestion('タイトル999', '問題文999', '選択肢1999', '選択肢2999', '選択肢3999', '選択肢4999', 3);
$quiz = new M_Quiz();
$title = 'クイズタイトルテスト0';
$quizlist = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
//クイズを作成
$quizId = $quiz->createQuiz($title, $quizlist);
}
示例5: setup
/**
* Sets up the session for the currently logged-in user, trying to re-establish a session for "remember-me" users who have been logged out,
* or creates a guest user object if no one is logged in.
*/
public function setup()
{
try {
// Initialize RememberMe
$storage = new \Birke\Rememberme\Storage\PDO($this->app->remember_me_table);
$storage->setConnection(\Illuminate\Database\Capsule\Manager::connection()->getPdo());
$this->app->remember_me = new \Birke\Rememberme\Authenticator($storage);
// Change cookie path
$cookie = $this->app->remember_me->getCookie();
$cookie->setPath("/");
$this->app->remember_me->setCookie($cookie);
// Determine if we are already logged in (user exists in the session variable)
if (isset($_SESSION["userfrosting"]["user_id"]) && $_SESSION["userfrosting"]["user_id"] != null) {
// Load the user. If they don't exist any more, throw an exception.
if (!($this->app->user = User::find($_SESSION["userfrosting"]["user_id"]))) {
throw new AccountInvalidException();
}
//error_log("Current user id is " . $this->app->user->id);
// Check, if the Rememberme cookie exists and is still valid.
// If not, we log out the current session
if (!empty($_COOKIE[$this->app->remember_me->getCookieName()]) && !$this->app->remember_me->cookieIsValid()) {
//error_log("Session expired. logging out...");
$this->app->remember_me->clearCookie();
throw new AuthExpiredException();
}
// If not, try to login via RememberMe cookie
} else {
// If we can present the correct tokens from the cookie, log the user in
// Get the user id
$name = $this->app->remember_me->getCookieName();
$user_id = $this->app->remember_me->login();
if ($user_id) {
//error_log("Logging in via remember me for $user_id");
// Load the user
$this->app->user = \UserFrosting\UserLoader::fetch($user_id);
// Update in session
$_SESSION["userfrosting"]["user_id"] = $user_id;
// There is a chance that an attacker has stolen the login token, so we store
// the fact that the user was logged in via RememberMe (instead of login form)
$_SESSION['remembered_by_cookie'] = true;
} else {
// If $rememberMe returned false, check if the token was invalid
if ($this->app->remember_me->loginTokenWasInvalid()) {
//error_log("Cookie was stolen!");
throw new AuthCompromisedException();
} else {
// $rememberMe returned false because of invalid/missing Rememberme cookie - create a dummy "guest" user
$this->app->user = new User([], $this->app->config('user_id_guest'));
}
}
}
// Now we have an authenticated user, setup their environment
$this->app->setupAuthenticatedEnvironment();
} catch (\PDOException $e) {
// If we can't connect to the DB, then we can't create an authenticated user. That's ok if we're in installation mode.
error_log("Unable to authenticate user, falling back to guest user.");
error_log($e->getTraceAsString());
}
}
示例6: configureDatabase
protected function configureDatabase()
{
$db = new DB();
$db->addConnection(array('driver' => 'sqlite', 'database' => ':memory:', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => ''));
$db->bootEloquent();
$db->setAsGlobal();
DB::connection()->enableQueryLog();
}
示例7: createMycelium
/**
* Create Mycelium service and setup fake Facade
*/
protected function createMycelium()
{
$configurationData = (require __DIR__ . "/../../src/config/mycelium.php");
$config = new \Illuminate\Config\Repository(["mycelium" => $configurationData]);
$connection = DB::connection();
$mycelium = new MyceliumManager($config, $connection);
$mycelium->createAndRegisterDefaultMounters();
$mycelium->createAndRegisterDefaultParsers("Europe/Prague");
// initialize fake facade
Mycelium::saveInstance($mycelium);
}
示例8: stripecx_link
function stripecx_link($params)
{
global $whmcs;
$pdo = Capsule::connection()->getPdo();
# Invoice Variables
$invoiceid = $params['invoiceid'];
$description = $params["description"];
$amount = $params['amount'];
# Format: ##.##
$currency = $params['currency'];
# Currency Code
# Client Variables
$email = $params['clientdetails']['email'];
$postcode = $params['clientdetails']['postcode'];
# System Variables
$companyname = $params['companyname'];
$systemurl = $params['systemurl'];
# Config Options
if ($params['validatezip'] == 'on') {
$zipCodeValidation = 'true';
} else {
$zipCodeValidation = 'false';
}
if ($params['rememberme'] == 'on') {
$RememberMe = 'true';
} else {
$RememberMe = 'false';
}
# Redirect If Checkout From Cart
$cart = $_REQUEST['a'];
if ($cart == 'complete') {
header('Location: viewinvoice.php?id=' . $invoiceid . '&stripecx');
}
# Auto-Start StripeCX?
if (isset($_REQUEST['stripecx'])) {
$start_sx = true;
} else {
$start_sx = false;
}
$sql = "SELECT * FROM stripecx_transactions WHERE invoice_id = '{$invoiceid}'";
$result = $pdo->query($sql);
$row = $result->fetch(PDO::FETCH_ASSOC);
if ($row) {
$pending_trans = "\n\t\t<script>\n\t\t\t\$(document).ready(function() {\n\t\t\t\t\$('select[name=\"gateway\"]').attr('disabled', 'disabled');\n\t\t\t\t\$('#StripeCXbutton').attr('disabled', 'disabled');\n\t\t\t\t\$('#StripeCXbutton').text('" . $whmcs->get_lang('clientareapending') . "');\n\t\t\t});\n\t\t\t\n\t\t\tfunction submit() {\n\t\t\t\t\t\n\t\t\t}\n\t\t</script>\n\t\t\n\t\t";
} else {
$pending_trans = NULL;
}
# Enter your code submit to the gateway...
$code = "\n\t<script src=\"https://checkout.stripe.com/v2/checkout.js\"></script>\n\t<script src=\"assets/js/jquery.js\"></script>\n\t\n\t" . $pending_trans . "\n\t<form>\n\t<button id=\"StripeCXbutton\">" . $params['langpaynow'] . "</button>\n</form>\n\t<script>\n\t\$ = jQuery;\t\t\n\t\n\t\tvar handler = StripeCheckout.configure({\n\t\t\tkey: '" . $params['public-key'] . "',\n\t\t\timage: '" . $params['image-url'] . "',\n\t\t\tcurrency: '" . $currency . "',\n\t\t\temail: '" . $email . "',\n\t\t\tzipCode: '" . $zipCodeValidation . "',\n\t\t\tallowRememberMe: '" . $RememberMe . "',\n\t\t\tdescription: '" . str_replace($companyname . " - ", "", $description) . "',\n\t\t\ttoken: function(token) {\n\t\t\t\t// Use the token to create the charge with a server-side script.\n\t\t\t\t// You can access the token ID with `token.id`\n\t\t\t\t\n\t\t\t\t\$('select[name=\"gateway\"]').attr('disabled', 'disabled');\n\t\t\t\t\$('#StripeCXbutton').attr('disabled', 'disabled');\n\t\t\t\t\$('#StripeCXbutton').text('" . $whmcs->get_lang('clientareapending') . "');\n\t\t\t\t\n\t\t\t\tstoreTransaction('" . $invoiceid . "',token.id, '" . $currency . "', '" . $amount * 100 . "');\n\t\t\t}\n\t\t});\n\t\t\n\t\tdocument.getElementById('StripeCXbutton').addEventListener('click', function(e) {\n\t\t\t// Open Checkout with further options\n\t\t\thandler.open({\n\t\t\t\tname: '" . $companyname . "',\n\t\t\t\tdescription: '" . str_replace($companyname . " - ", "", $description) . "',\n\t\t\t\tamount: " . $amount * 100 . "\n\t\t\t});\n\t\t\te.preventDefault();\n\t\t});\n\t\t \n\t\tfunction storeTransaction(sid,stoken,currency, amount) {\n\t\t\t \n\t\t\turl = document.URL;\n\t\t\turl = url.substring(0, url.lastIndexOf('/') + 1);\n\t\t\t \n\t\t\t\$.ajax({\n\t\t\t\tdata: { id: sid, token: stoken, currency: currency, amount: amount },\n\t\t\t\turl: url+'modules/gateways/stripecx/callback.php',\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tsuccess: function(data) {\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t</script>\n\t";
if ($start_sx == true) {
$code = $code . "\n\t\t<script>\n\t\t\tdocument.getElementById('StripeCXbutton').click();\n\t\t</script>\n\t\t";
}
return $code;
}
示例9: makeConnection
/**
* create connection to the database based on given configuration
*/
private function makeConnection($config)
{
try {
$capsule = new Capsule();
$capsule->addConnection($config);
$capsule->setAsGlobal();
$capsule->bootEloquent();
Sentry::setupDatabaseResolver($capsule->connection()->getPdo());
} catch (Exception $e) {
throw $e;
}
}
示例10: IsConnected
/**
* Are we connected?
*
* @return bool
*/
public function IsConnected()
{
/**
* Try (So we return a bool no matter what and don't crash and burn ahhh)
*/
try {
/**
* If we can get our database name
*/
if ($this->capsule->connection()->getDatabaseName()) {
return true;
}
/**
* Else, return false
*/
return false;
} catch (\Exception $error) {
/**
* Just incase we error
*/
return false;
}
}
示例11: register
/**
* Register the Capsule service.
*
* @param Silex\Application $app
* @return void
**/
public function register(Application $app)
{
$app['capsule.connection_defaults'] = ['driver' => 'mysql', 'host' => 'localhost', 'database' => null, 'username' => 'root', 'password' => null, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null, 'logging' => false];
$app['capsule.global'] = true;
$app['capsule.eloquent'] = true;
$app['capsule.container'] = $app->share(function () {
return new Container();
});
$app['capsule.dispatcher'] = $app->share(function () use($app) {
return new Dispatcher($app['capsule.container']);
});
$app['capsule'] = $app->share(function ($app) {
$capsule = new Capsule($app['capsule.container']);
$capsule->setEventDispatcher($app['capsule.dispatcher']);
if ($app['capsule.global']) {
$capsule->setAsGlobal();
}
if ($app['capsule.eloquent']) {
$capsule->bootEloquent();
}
if (!isset($app['capsule.connections'])) {
$app['capsule.connections'] = ['default' => isset($app['capsule.connection']) ? $app['capsule.connection'] : []];
}
foreach ($app['capsule.connections'] as $connection => $options) {
$options = array_replace($app['capsule.connection_defaults'], $options);
$logging = $options['logging'];
unset($options['logging']);
$capsule->addConnection($options, $connection);
if ($logging) {
$capsule->connection($connection)->enableQueryLog();
} else {
$capsule->connection($connection)->disableQueryLog();
}
}
return $capsule;
});
}
示例12: getColumnsNames
public function getColumnsNames(array $arAdditionalField = [])
{
if ($this->allFields) {
return $this->allFields;
}
/* $connection = DB::connection();
$connection->getSchemaBuilder();
$results = $connection->select('PRAGMA table_info('.$this->table.')');
$results = $connection->getPostProcessor()->processColumnListing($results);
*/
$results = DB::connection()->getSchemaBuilder()->getColumnListing($this->table);
$this->allFields = array_merge($results, $arAdditionalField);
return $this->allFields;
}
示例13: registerDatabase
/**
* Register Eloquent database in Slim app (use Model now)
*
* @return Shiniwork $this
*/
protected function registerDatabase()
{
$container = $this->getContainer();
$settings = $container->get('settings');
if (!empty($settings['database'])) {
$capsule = new Manager();
$capsule->addConnection($settings['database']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
if ($container->getMode() === 'development') {
$capsule->connection()->enableQueryLog();
}
}
return $this;
}
示例14: register
/**
* Register the Illuminate Database service
*
* @param Silex\Application
*/
public function register(Application $app)
{
$app['db.connection_defaults'] = array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null);
$app['db.boot'] = true;
$app['db.global'] = true;
$app['db.container'] = $app->share(function () {
return new Container();
});
$app['db.dispatcher'] = $app->share(function () use($app) {
return new Dispatcher($app['db.container']);
});
if (class_exists('\\Illuminate\\Cache\\CacheManager')) {
$app['db.cache_manager'] = $app->share(function () use($app) {
return new \Illuminate\Cache\CacheManager($app['db.container']);
});
}
$app['db.cache'] = array('driver' => 'apc', 'prefix' => 'laravel');
$app['db'] = $app->share(function () use($app) {
$db = new Capsule($app['db.container']);
$db->setEventDispatcher($app['db.dispatcher']);
if (isset($app['db.cache_manager']) && isset($app['db.cache'])) {
$db->setCacheManager($app['db.cache_manager']);
foreach ($app['db.cache'] as $key => $value) {
$app['db.container']->offsetGet('config')->offsetSet('cache.' . $key, $value);
}
}
if ($app['db.global']) {
$db->setAsGlobal();
}
if ($app['db.boot']) {
$db->bootEloquent();
}
if (!isset($app['db.connections'])) {
$connection = array();
if (isset($app['db.connection'])) {
$connection = $app['db.connection'];
}
$app['db.connections'] = array('default' => $connection);
}
foreach ($app['db.connections'] as $connection => $options) {
$db->addConnection(array_replace($app['db.connection_defaults'], $options), $connection);
}
if (!$app['debug']) {
$db->connection()->disableQueryLog();
}
return $db;
});
}
开发者ID:mattkirwan,项目名称:illuminate-database-silex-service-provider,代码行数:53,代码来源:IlluminateDatabaseServiceProvider.php
示例15: assertTreeNotBroken
public function assertTreeNotBroken($table = 'categories')
{
$checks = array();
// Check if lft and rgt values are ok
$checks[] = "from {$table} where _lft >= _rgt or (_rgt - _lft) % 2 = 0";
// Check if lft and rgt values are unique
$checks[] = "from {$table} c1, {$table} c2 where c1.id <> c2.id and " . "(c1._lft=c2._lft or c1._rgt=c2._rgt or c1._lft=c2._rgt or c1._rgt=c2._lft)";
// Check if parent_id is set correctly
$checks[] = "from {$table} c, {$table} p, {$table} m where c.parent_id=p.id and m.id <> p.id and m.id <> c.id and " . "(c._lft not between p._lft and p._rgt or c._lft between m._lft and m._rgt and m._lft between p._lft and p._rgt)";
foreach ($checks as $i => $check) {
$checks[$i] = 'select 1 as error ' . $check;
}
$sql = 'select max(error) as errors from (' . implode(' union ', $checks) . ') _';
$actual = (array) Capsule::connection()->selectOne($sql);
$this->assertEquals(array('errors' => null), $actual, "The tree structure of {$table} is broken!");
}