Example #1
0
 public function insert()
 {
     if (!is_null($this->id)) {
         trigger_error("User::insert(): Attempt to insert a user object that already has its ID property set to {$this->id}.", E_USER_ERROR);
     }
     $conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
     $sql = "INSERT INTO " . TABLENAME_REQUESTS . " ( type, sentById, sentToId, status ) VALUES ( :type, :sentById, :sentToId, :status)";
     $st = $conn->prepare($sql);
     $st->bindValue(":type", $this->type, PDO::PARAM_STR);
     $st->bindValue(":sentById", $this->sentById, PDO::PARAM_INT);
     $st->bindValue(":sentToId", $this->sentToId, PDO::PARAM_INT);
     $st->bindValue(":status", $this->status, PDO::PARAM_STR);
     //	print_r( $st );
     $result = $st->execute();
     $this->id = $conn->lastInsertId();
     $conn = null;
     if (!$result) {
         self::$errorMessage = "User::insert: Insertion Failed, PDO::errorInfo(): " . $st->errorCode() . ": " . $st->errorInfo()[2];
         self::$errorCode = $st->errorCode();
         //echo $errorMessage;
         return false;
     } else {
         self::$successMessage = "User::insert: User successfully inserted with id " . $this->id;
         return true;
     }
 }