Example #1
0
 /**
  * Prepares an SQL statement.
  *
  * @param  string  $sql  The query to prepare.
  * @return void
  */
 public function prepare(string $sql) : Statement
 {
     // Prepare the query.
     $this->stmt = Database::connection()->prepare($this->sql = $sql);
     // Return class.
     return $this;
 }
Example #2
0
 /**
  * Saves the record.
  *
  * @return bool
  */
 public function save() : bool
 {
     // Get the model attributes.
     $attributes = $this->attributes();
     // Remove guarded attributes.
     foreach ($this->guarded as $guarded) {
         if (isset($attributes[$guarded])) {
             unset($attributes[$guarded]);
         }
     }
     // Instantiate query.
     $query = static::query();
     // If we have an id then update the record.
     if ($this->hasAttribute('id')) {
         $query = $query->where('id', '=', $this->getAttribute('id'));
         $saved = $query->edit($attributes);
     } else {
         $saved = $query->create($attributes);
         // If successfully created, add the insert id.
         if ($saved) {
             $this->setAttribute('id', Database::insertId());
         }
     }
     // Return true if successfully saved.
     return $saved;
 }
Example #3
0
 /**
  * Close the system.
  *
  * @return void
  */
 public static function close()
 {
     Session::finalize();
     Database::finalize();
 }