public static function start($host, $root, $password, $database)
 {
     if (!isset(self::$connection)) {
         self::$connection = new mysqli($host, $root, $password, $database);
         if (mysqli_connect_errno()) {
             printf("Connect failed: %s\n", mysqli_connect_error());
             exit;
         }
     }
 }
Пример #2
0
 private static function loadEntities()
 {
     $str = file_get_contents(Settings::get('entities'));
     echo $str;
     $entities = new SimpleXMLElement($str);
     foreach ($entities->entity as $entity) {
         $ent = new SimpleORM_Entity();
         $ent->name = "{$entity['name']}";
         foreach ($entity->field as $field) {
             $f = new SimpleORM_Field();
             $f->name = "{$field['name']}";
             $f->isKey = "{$field['key']}" == 'yes' ? true : false;
             $f->isNull = "{$field['null']}" == 'yes' ? true : false;
             $f->relationship = strlen("{$field['relationship']}") == 0 ? SimpleORM_Field::one_to_one : "{$field['relationship']}";
             $f->isUnique = "{$field['unique']}" == 'yes' ? true : false;
             $f->entity = strlen("{$field['entity']}") == 0 ? null : self::getEntity("{$field['entity']}");
             if (strlen($f->name) == 0) {
                 $f->name = $f->entity->name;
             }
             $f->type = strlen("{$field['type']}") == 0 ? 'varchar(255)' : "{$field['type']}";
             if ($f->isKey) {
                 $ent->setID($f);
             }
             $ent->addField($f);
             //echo "name: $f->name unique:$f->isUnique relationship:$f->relationship entity:$f->entity<br>";
         }
         self::$entities[$ent->name] =& $ent;
     }
     if (Settings::get('auto_create_table') == 'yes') {
         foreach (self::$entities as $entity) {
             foreach ($entity->createStmts() as $stmt) {
                 try {
                     SimpleORM_Connection::execute($stmt);
                 } catch (Exception $e) {
                     //Logger::logException($e);
                     echo $e->getMessage();
                     echo "<br>";
                     echo $e->getTraceAsString();
                 }
             }
         }
     }
 }
Пример #3
0
 public function query($criterium = null, $restriction = null)
 {
     $stmt = sprintf('select  %s from %s %s %s', implode(', ', $this->entity->getSingulars()), $this->entity->name, strlen(trim("{$criterium}")) == 0 ? '' : " where {$criterium}", $restriction == null ? '' : " {$restriction}");
     return $this->toObject(SimpleORM_Connection::query($stmt));
 }
 public function __toString()
 {
     return sprintf("%s = '%s'", $this->field, SimpleORM_Connection::escape($this->values[0]));
 }