Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 public static function setDb($db)
 {
     self::$db = $db;
 }
Esempio n. 4
0
<?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();
}
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public static function setDb(Mysqli $mysqli)
 {
     self::$db = $mysqli;
 }
Esempio n. 7
0
 /**
  * Setup test databases.
  */
 protected function setUp()
 {
     $this->executeSqlFile('models/ColumnTest.sql');
     Table::$db = ActiveRecord::$db = $this->createDbConnection('columntest');
 }
Esempio n. 8
0
 /**
  *  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();
     }
 }