Esempio n. 1
0
 function setUp()
 {
     parent::setUp();
     $this->conn = new Mongo('mongodb://localhost');
     if ($this->conn) {
         $this->db = $this->conn->testdb;
         BaseMongoRecord::$connection = $this->conn;
         BaseMongoRecord::$database = 'testdb';
     }
 }
Esempio n. 2
0
        $GLOBALS['SK']['DB']['HOST'] = '';
        $GLOBALS['SK']['DB']['USER'] = '';
        $GLOBALS['SK']['DB']['PASS'] = '';
        break;
    case 'production':
    default:
        $GLOBALS['SK']['DB']['DRIVER'] = 'sqlite';
        // mongodb, mysql, pgsql, oci, sqlite
        $GLOBALS['SK']['DB']['FILE'] = 'test.db';
        // only sqlite
        $GLOBALS['SK']['DB']['NAME'] = '';
        $GLOBALS['SK']['DB']['HOST'] = '';
        $GLOBALS['SK']['DB']['USER'] = '';
        $GLOBALS['SK']['DB']['PASS'] = '';
        break;
}
if ('mongodb' === $GLOBALS['SK']['DB']['DRIVER']) {
    BaseMongoRecord::$connection = new Mongo('mongodb://' . $GLOBALS['SK']['DB']['USER'] . ':' . $GLOBALS['SK']['DB']['PASS'] . '@' . $GLOBALS['SK']['DB']['HOST'] . '/' . $GLOBALS['SK']['DB']['NAME']);
    BaseMongoRecord::$database = $GLOBALS['SK']['DB']['NAME'];
} else {
    $dbcfg = ActiveRecord\Config::instance();
    $dbcfg->set_model_directory(path('app.model'));
    if ('sqlite' === $GLOBALS['SK']['DB']['DRIVER']) {
        $dbcfg->set_connections(array(env() => 'sqlite:' . path('storage.database', true) . $GLOBALS['SK']['DB']['FILE']));
    } else {
        $dbcfg->set_connections(array(env() => $GLOBALS['SK']['DB']['DRIVER'] . '://' . $GLOBALS['SK']['DB']['USER'] . ':' . $GLOBALS['SK']['DB']['PASS'] . '@' . $GLOBALS['SK']['DB']['HOST'] . '/' . $GLOBALS['SK']['DB']['NAME']));
    }
    ActiveRecord\Config::initialize(function ($dbcfg) {
        $dbcfg->set_default_connection(env());
    });
}
<?
require_once '../lib/BaseMongoRecord.php';
$dbusername="******";
$dbpassword="******";
BaseMongoRecord::$database = 'foodb';
BaseMongoRecord::$connection = new Mongo("mongodb://${dbusername}:${dbpassword}@localhost/".BaseMongoRecord::$database);

class Student extends BaseMongoRecord
{
  protected $belong_to=array('School');
  /**
      can add more targets with-> $belong_to=array('ClsA','ClsB',...)
      below methods are genereated automaticlly:
      $this->getSchool();//return school
      $this->setSchool($school);//return $this
    */


}

class School extends BaseMongoRecord
{
  protected $has_many=array('Student');
  /** 
       Can add more targets with-> $has_many=array('ClsA','ClsB',...)
       below methods are genereated automaticlly:
       $this->getStudents();//return MongoRecordIterator
       $this->setStudents($stuarray);//parm is array of students,return $this
       $this->createStudent();//new student and return it,return student
       $this->addStudent($stu);//parm is student instante,return $this
       $this->removeStudent($stu);//parm is student instant,return $this