- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如何选择我的 ORM 应使用的数据库配置?该文档仅提及如何设置配置并在使用纯数据库方法时选择它。使用 ORM 时不是。
这是我当前的配置:
控制者
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller {
public function action_index()
{
$members = ORM::factory('user');
$members->where('first_name', '=', 'Peter')->find_all();
$memCount = $members->count_all();
$this->response->body('Count: ' . $memCount);
}
} // End Welcome
型号
<?php defined('SYSPATH') or die('No direct access allowed.');
class Model_User extends ORM
{
protected $_primary_key = 'UserId';
}
配置(位于application/config/database.php
<?php defined('SYSPATH') or die('No direct access allowed.');
return array
(
'local' => array
(
'type' => 'mysql',
'connection' => array(
'hostname' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => '*******',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
'remote' => array(
'type' => 'pdo',
'connection' => array(
'dsn' => 'mysql:host=localhost;dbname=kohana',
'username' => 'root',
'password' => '***',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
);
我只想让 ORM 使用 local
数据库。我该怎么做呢?现在我收到错误:Database_Exception [2]: mysql_connect(): Access denied for user 'www-data'@'localhost' (using password: NO)
最佳答案
如 Kowser 所说,对于要使用“本地”数据库组返回连接的 Database::instance(),请使用 Database::$default = 'local';
如果你想让一个类使用一个不是Database::$default的特定数据库组。然后在您的类定义中将 $_db_group 设置为数据库配置组,如下所示:
<?php defined('SYSPATH') or die('No direct access allowed.');
class Model_User extends ORM
{
protected $_db_group = 'local';
protected $_primary_key = 'UserId';
}
通过这种方式,您可以将 Database::$default 设置为“远程”,并且只有该类的对象才会使用“本地”连接。
关于php - ORM 的 Kohana 数据库配置设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8298934/
我一直在使用 Kohana 2.3.7。有一些因素阻碍我们使用 Kohana 3,其中之一是与 2.3.7 相比缺少模块。例如,我似乎找不到2.3至3中存在的支付模块(Paypal、2C0、Autho
如果我在 https://www.example.com/test?page=123 页面上,我如何使用 Kohana 获得这个完整路径(proto + host + URI + query)? 我试
在我的应用程序中,我有一个执行大约 1000 次的循环,在其中我创建对象并保存它。这是应用程序的一部分,我用数据填充数据库。一般来说,这看起来像这样: foreach(...){ ...
如果我在 https://www.example.com/test?page=123 页面上,我如何使用 Kohana 获得这个完整路径(proto + host + URI + query)? 我试
我正在使用 ORM Auth 模块,但很难弄清楚如何做到这一点。我尝试过这种情况: $user = ORM::factory('user', $id);$user->roles->delete_all
好的,我试过到处搜索,但似乎无法得到一个简单直接的答案。 我想将日志消息( INFO 、 ERROR 等)写入 Kohana 日志文件 /application/logs/YYYY/MM/DD.php
我的问题是关于多词 MySQL 表名的约定,例如“comments_flags”,它不是数据透视表。 “comments_flags”的正确数据库表名是什么? 相应的型号名称是什么? 感谢您的任何建议
尝试在我的 Kohana 2.3.4 安装上运行 PHPUnit: phpunit --colors --bootstrap=index.php ../../modules/phpunit/libra
我是 kohana 的新手。我正在使用 ORM 来获取数据。 我想建立一个查询,其中 BETWEEN条款在那里。如下 SELECT `rooms`.* FROM `rooms` LEFT JOIN `
在 Kohana 3.3 的 DOCROOT 文件夹中,有一个新的 vendor 文件夹。 它有什么用? 最佳答案 它不应该在那里。这是 Composer 留下的。 关于kohana - Kohana
如何让它发挥作用? $stuff = ORM::factory('mytable') ->with('user') ->with('other_stuff') ->find_a
我注意到,当我开始使用它们时,Kohana 3 ORM 会为我的每个模型运行“显示完整列”: SHOW FULL COLUMNS FROM `mytable` 此查询可能需要几个时钟周期才能执行(在
全新安装了 Kohana 3.1。试图让我自己的 helper 。我在 application/classes/helpers/目录中创建了一个助手。我调用了文件 javascript.php,该类称
在 Kohana 2.x 中,有一个 $file = Kohana::log_directory(); 可以根据发送的参数获取或设置目录。 如何在Kohana 3.1下得到类似的效果? 我想读取日志目
使用 native ORM 在 Kohana(3.3) 中防止 SQL 注入(inject)的最佳方法是什么? 或者默认情况下它是“安全的”.. 最佳答案 默认情况下是安全的,因为它使用 Kohana
如何在 Kohana 3.2 中调用验证对象的 trim 函数?我正在使用: $post = Validation::factory($this->request->post()); $post->r
首先,我对 kohana 很陌生,但我对更流行的 Yii 和 Yii2 有丰富的经验。 我正在处理复杂的配置,它使用查询生成器从跳跃模型调用 MsSQL 数据库。现在我不得不优化代码,但遇到了一个错误
我正在尝试在 Kohana 3.3.0 中将 Auth 模块与 ORM 驱动程序一起使用,但我唯一能做的就是在数据库中插入新用户。我不能用他们登录。 我从一个空白的 Kohana 项目、一个简单的路由
我有一个简单的users表,我想找到所有用户在哪里email_notifications = 1。 逻辑规定以下应该起作用: class Controller_Test extends Control
我需要生成这样的查询: SELECT * FROM `table1` WHERE `date1` where('date1','execute(); $foo = array(); foreach (
我是一名优秀的程序员,十分优秀!