本文整理汇总了PHP中ActiveRecord::db方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::db方法的具体用法?PHP ActiveRecord::db怎么用?PHP ActiveRecord::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::db方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connectDb
/**
* Connects to the specified schema and assigns it to all models which need it.
*
* @return CDbConnection
*/
protected function connectDb($schema)
{
// Connect to database
$connectionString = 'mysql:host=' . Yii::app()->user->host . ';port=' . Yii::app()->user->port . ';dbname=mysql';
$this->db = new CDbConnection($connectionString, Yii::app()->user->name, Yii::app()->user->password);
$this->db->charset = 'utf8';
$this->db->emulatePrepare = true;
$this->db->active = true;
// Assign to all models which need it
ActiveRecord::$db = SchemaPrivilege::$db = $this->db;
// Return connection
return $this->db;
}
示例2: connectDb
/**
* Connects to the specified schema and assigns it to all models which need it.
*
* @param $schema schema
* @return CDbConnection
*/
protected function connectDb($schema)
{
// Assign request
$this->request = Yii::app()->getRequest();
// Check parameter
if (is_null($schema)) {
$this->db = null;
return null;
}
// Connect to database
$connectionString = 'mysql:host=' . Yii::app()->user->host . ';port=' . Yii::app()->user->port . ';dbname=' . $schema . '; charset=utf8';
$this->db = new CDbConnection($connectionString, utf8_decode(Yii::app()->user->name), utf8_decode(Yii::app()->user->password));
$this->db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES \'utf8\'');
$this->db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET CHARACTER SET \'utf8\'');
$this->db->charset = 'utf8';
$this->db->emulatePrepare = true;
$this->db->active = true;
// Schema name is set in connection string
// $this->db->createCommand('USE ' . $this->db->quoteTableName($schema))->execute();
// Assign to all models which need it
ActiveRecord::$db = Routine::$db = Row::$db = Trigger::$db = View::$db = $this->db;
// Return connection
return $this->db;
}
示例3: setDb
public static function setDb($db)
{
self::$db = $db;
}
示例4: PDO
<?php
error_reporting(E_ALL);
define("ROOT", '..');
require ROOT . "/ini.php";
require ROOT . "/lib/activerecord.php";
require ROOT . "/lib/persistance.php";
ActiveRecord::$db = new PDO($ini['db']);
class User implements persistance
{
static $table;
function gul_assalam()
{
print $this->name . " : Aya golna slam3likom <br />";
}
function insert()
{
return self::$table->insert($this);
}
static function select($options = NULL)
{
return self::$table->select($options);
}
}
User::$table = new ActiveRecord("users", "User");
$users = User::select();
foreach ($users as $u) {
$u->gul_assalam();
$u->name = "Changed my name";
$u->insert();
}
示例5: initialize
public static function initialize($func)
{
self::$config = $func();
self::$db = ActiveRecord\Connection::getInstance(self::$config['connectionString'], self::$config['user'], self::$config['password']);
self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
示例6: setDb
public static function setDb(Mysqli $mysqli)
{
self::$db = $mysqli;
}
示例7: setUp
/**
* Setup test databases.
*/
protected function setUp()
{
$this->executeSqlFile('models/ColumnTest.sql');
Table::$db = ActiveRecord::$db = $this->createDbConnection('columntest');
}
示例8: elseif
/**
* Construct an ActiveRecord object
*
* <ol>
* <li>Establish a connection to the database</li>
* <li>Find the name of the table associated with this object</li>
* <li>Read description of this table from the database</li>
* <li>Optionally apply update information to column attributes</li>
* </ol>
* @param string[] $attributes Updates to column attributes
* @uses establish_connection()
* @uses set_content_columns()
* @uses $table_name
* @uses set_table_name_using_class_name()
* @uses reset_attributes()
* @uses update_attributes()
*/
function __construct($attributes = null)
{
# Open the database connection for reads / writes
self::$db = $this->establish_connection();
if ($this->read_only_connection_name) {
# Open database connection for all reads
$this->establish_connection($this->read_only_connection_name, true);
} elseif (self::$global_read_only_connection_name) {
# Open database connection for all reads
$this->establish_connection(self::$global_read_only_connection_name, true);
}
# Set $table_name
if ($this->table_name == null) {
$this->set_table_name_using_class_name();
}
# Set column info
if ($this->table_name) {
$this->set_content_columns($this->table_name);
}
# If $attributes array is passed in update the class with its contents
if (!is_null($attributes)) {
$this->update_attributes($attributes);
}
# If callback is defined in model run it.
# this could hurt performance...
if (method_exists($this, 'after_initialize')) {
$this->after_initialize();
}
}