Exemplo n.º 1
0
 public function store_insert($force = false)
 {
     ##
     static::schemadb_update();
     ##
     $c = [];
     $v = [];
     $k = static::primary_key();
     ##
     foreach (static::skema() as $f => $d) {
         ##
         if ($f == $k && !$force) {
             continue;
         }
         ##
         $a = $this->{$f};
         $t = gettype($a);
         ##
         switch ($t) {
             ##
             case 'double':
                 $a = number_format($a, 2, '.', '');
                 break;
                 ##
             ##
             case 'array':
                 schemadb::object_build($d, $a, $r);
                 $a = $r;
                 break;
         }
         ##
         $a = schemadb::escape($a);
         ##
         $c[] = $f;
         $v[] = "'" . $a . "'";
     }
     ##
     $c = implode(',', $c);
     $v = implode(',', $v);
     ##
     $t = static::table();
     $q = "INSERT INTO {$t} ({$c}) VALUES ({$v})";
     ##
     schemadb::execute('query', $q);
     ##
     if ($k) {
         $i = schemadb::execute('last_id');
         $this->{$k} = $i;
         return $i;
     } else {
         return true;
     }
 }