Exemplo n.º 1
0
 /**
  * Create a new object instance and read it from the database, populating the object attributes
  * @param mixed $params Object to read.
  *   This can be an instance ID or a parameter array.
  * @param \PDO $db Database connection to use
  * @return \Sonic\Model
  */
 public static function _read($params, &$db = FALSE)
 {
     // Create the object
     $obj = new static();
     // If the params are an array
     if (is_array($params)) {
         // Select all
         $params['select'] = '*';
         // Get data
         $row = static::_getValue($params, \PDO::FETCH_ASSOC, $db);
         // If no data was returned return FALSE
         if (!$row) {
             return FALSE;
         }
         // Set each attribute value
         foreach ($row as $name => $val) {
             if ($obj->attributeExists($name)) {
                 $obj->iset($name, $val);
             }
         }
     } else {
         // Read the object
         if (!$obj->read($params, $db)) {
             return FALSE;
         }
     }
     // Return the object
     return $obj;
 }
Exemplo n.º 2
0
 /**
  * 设置从库的连接以及打开从库,随机打开一个从库连接
  * @example 设置从库 DB::r([ ["mysql:dbname=taijimr;host=127.0.0.1","test","test"] ]);
  * @example 读取从库 DB::r();
  * @param int $db 可指定要打开的从库的第几个   
  * @return DBobject
  */
 static function r($db = NULL)
 {
     if (!isset(static::$read)) {
         $i = array_rand($db, 1);
         $config = $db[$i];
         if (!$config) {
             $config = $db;
         }
         static::$read = new Static($config[0], $config[1], $config[2]);
     }
     $default = 'r';
     static::$mark[$default] = $default;
     unset(static::$read[$default]->ar, static::$read[$default]->where);
     return static::$read;
 }
Exemplo n.º 3
0
 /**
  * Static access to reader
  *
  * @param  InputInterface $input
  * @return Configuration
  */
 public static function readInput(InputInterface $input)
 {
     $reader = new static($input);
     return $reader->read();
 }